วิธี SSH ข้ามเซิฟเวอร์โดยไม่ใส่รหัสผ่าน

ยกตัวอย่างเช่น ssh จากเครื่อง A ไปเครื่อง B โดยไม่ใช้รหัสผ่านในการ ssh

@เครื่อง A
ssh-keygen -t rsa
(มีอะไรขึ้นมาก็กด enter ผ่านไปให้หมด แล้วพิมพ์คำสั่งด้านล่าง เพื่อเตรียมก็อบค่าไว้)
cat /root/.ssh/id_rsa.pub
id_rsa.pub = publickey ก๊อปไปใส่เครื่องปลายทาง B
id_rsa = privatekey เก็บไว้บนเครื่องต้นทาง A
แบบดี ๆ หน่อยก็ ssh-keygen -t ed25519 แล้วใส่ passphrase เพื่อกรอกพาสอีกครั้งกันเหนียวเวลา privatekey/putty.ppk หลุด

@เครื่อง B
vim /root/.ssh/authorized_keys
ก็อบค่า id_rsa.pub ของเครื่อง A มาใส่(ต่อท้าย กรณีทำ A หลายเครื่อง)

คราวนี้ลอง ssh จากเครื่อง A -> B โดยไม่ต้องใส่พาสก็ได้แล้วล่ะ

+ล๊อคอินแบบไม่ใช้พาส
vim /etc/ssh/sshd_config
เปลี่ยน #PermitRootLogin yes เป็น PermitRootLogin without-password เพื่อใช้ rsa ด้านบนคอนเฟิร์มแม้จะพิมพ์พาส root ถูก
หรือเปลี่ยน PasswordAuthentication yes เป็น no เพื่อบังคับไม่ใช้ password ตั้งแต่ล๊อคอินในการเข้าใช้งาน

หรือจัดเต็ม
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
service sshd restart

rsa with allowip https://unix.stackexchange.com/a/490120
vim /etc/ssh/sshd_config
AllowUsers [email protected].* [email protected].* otherid1

vim /root/.ssh/authorized_keys
from="192.168.1.*,192.168.2.*" ssh-rsa AAAAB3NzaC1yc2EAA........

ref: blog.rtsp.us/–9dc83e2aaa90
ref: linuxproblem.org/art_9.html
ref: thaicert.nectec.or.th/paper/encryption/ssh_key_authentication.php



check ssh login
journalctl -u sshd --since -3d | grep "Accepted password for root"
journalctl -u sshd --since -3d | grep "198.23.148.137"
cat /var/log/auth.log* | grep "Accepted password for"
cat /var/log/secure-* | grep "password changed for"

Blog | , ,
Line it!