SSH Key ເປັນການປ່ຽນການ Authentication ໃນຮູບແບບການໃສ່ username , password ປ່ຽນເປັນການໃຊ້ງານ key pair ແທນ ຄືການໃຊ້ງານ public key ແລະ private key ຂໍ້ດີຄື ປອດໄພກວ່າການໃຊ້ງານ password ໃນເລື່ອງຂອງການຖືກ Brute Force Attack ,ຫລື ຖືກໂປຣແກຣມປະເພດ Key Logger ດັກ keyboard ເປັນຕົ້ນ ໂດຍເຮົາສາມາດເພີ່ມຄວາມ Secure ໄປໄດ້ອີກຊັ້ນຄື ສາມາດຕັ້ງລະຫັດ passphrase ດ້ວຍກໍ່ໄດ້
Image does not exist: https://image.ibb.co/mEnE4v/key_based_authentication.jpg
ເຄື່ອງທີ່ໃຊ້ໃນການທົດສອບເທື່ອນີ້ມີ
sv1 - 172.16.209.137 (ສ້າງ key ແລະໃຊ້ງານ private key) sv2 - 172.16.209.138 (ທົດສອບໃຊ້ງານ public key) ກະບວນການເຮັດວຽກງານຂອງ SSH Key Pair 1 )
ເລີ່ມດ້ວຍການ generate Public Key ແລະ Private Key
ssh-keygen -t rsa
Image does not exist: https://image.ibb.co/hwg7Pv/sshkeygen.png
ຫາກຕ້ອງການໃຊ້ງານ Passphrase ກໍ່ຕັ້ງລະຫັດຜ່ານໄດ້ເລີຍ ໃນທີ່ນີ້ຂ້າພະເຈົ້າຈະກົດ enter ເລີຍບໍ່ຕັ້ງລະຫັດຜ່ານ (Passphrase ເວົ້າງ່າຍໆຄື Master Password ເອົາໄວ້ກັ້ນການໃຊ້ງານ Key ນັ້ນເອງ)
Image does not exist: https://image.ibb.co/dnnsra/sshkeygen1.png
ຫຼັງສຳເລັດກະບວນການນີ້ກໍໍ່ຈະໄດ້ໄຟລ໌ມາ 2 ໄຟລ໌ຄື Private Key (/root/.ssh/id_rsa) ກັບ Public Key (/root/.ssh/id_rsa.pub) ໂດຍການໃຊ້ງານຄື ເຮົາຈະນຳເອົາ Public Key ໄປໃສ່ໄວ້ໃນ Server ທີ່ເຮົາຕ້ອງການ ແລະ ເກັບ Private Key ໄວ້ສຳລັບ remote access ເຂົ້າໄປເຄື່ອງເຊິເວີທີ່ມີ Public Key ຝັງຢູ່ນັ້ນເອງ ທົດສອບນຳ Public Key ໄປໃສ່ໄວ້ເຄື່ອງ sv2
ssh-copy-id [email protected]
ຫລື ນຳໄຟລ໌ Public Key ໄປໃສ່ໄວ້ທີ່ Path ~/.ssh/authorized_keys
Image does not exist: https://image.ibb.co/cFXsra/sshkeygen2.png
ທົດສອບ Login ອີກເທື່ອໂດຍໃຊ້ງານ Key
ssh [email protected]
Image does not exist: https://image.ibb.co/gfKu4v/sshkeygen3.png
ສັງເກດວ່າຈະສາມາດ remote ssh ໄດ້ໂດຍທີ່ບໍ່ມີການຖາມ Password ເພາະວ່າໂດຍ default ແລ້ວ linux ຈະອ່ານ private key ຈາກໄຟລ໌ ~/.ssh/id_rsa ຈາກຂັ້ນຕອນຂ້າງຕົ້ນຂ້າພະເຈົ້າໄດ້ໃສ່ private key ໄວ້ຈຶ່ງເຮັດໃຫ້ສາມາດ remote ໄດ້ເລີຍແຕ່ຖ້າຫາກບໍ່ໄດ້ມີການໃສ່ private key ໄວ້ໃນໄຟລ໌ນີ້ກໍ່ໃຫ້ທຳການຮຽກ Private Key ໂດຍໃຊ້ Argument -i ແທນ ເຊັ່ນ
ssh -i /path/key [email protected]
ກະບວນການໃຊ້ງານ SSH Key ກໍ່ມີເທົ່ານີ້ ຕໍ່ໄປເຮົາຈະມາ Config SSH ເພື່ອປິດການໃຊ້ງານ Password ກັນຕໍ່ໂດຍເຂົ້າໄປແກ້ໄຂໄຟລ໌
/etc/ssh/sshd_config
ໂດຍປ່ຽນຈາກ
#PermitRootLogin yes
ແກ້ໄຂເປັນ
PermitRootLogin without-password
Image does not exist: https://image.ibb.co/e4Z2Pv/permitrootlogin.png
ຫາກລອງທົດສອບ login ດ້ວຍ Password ເບິ່ງກໍ່ຈະບໍ່ສາມາດ Access ໄດ້ເລີຍ
Image does not exist: https://image.ibb.co/ispmjv/testrootlogin.png