//單向免密登陸
//A端
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
# ssh-keygen -t rsa //生成公鑰與私鑰(運行該命令後 三次 回車)
# ssh-copy-id [B端ip] //需要輸入B端密碼
# ssh [B端ip] //免密登錄成功
//B端
# cat /etc/redhat-release
CentOS release 6.8 (Final)
//互免密登陸
//注意:在本示例中使用的用戶是root,如果使用其他用戶時,A端與B端要存在相同名稱的用戶
//系統 CentOS Linux release 7.7.1908 (Core)
//A端 ip:192.168.56.10
# ssh-keygen -t rsa -P ''
# chmod 600 ~/.ssh/authorized_keys //一般.ssh目錄下存在authorized_keys文件,如不存在則手動創建並修改權限爲600
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# scp ~/.ssh/id_rsa.pub root@[B端ip]:~ //把id_rsa.pub拷貝給B端,複製粘貼id_rsa.pub內容到B端也可
# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys //追加到authorized_keys中
//系統 CentOS Linux release 7.7.1908 (Core)
//B端 ip:192.168.56.20
# ssh-keygen -t rsa -P ''
# chmod 600 ~/.ssh/authorized_keys
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# scp ~/.ssh/id_rsa.pub root@[A端ip]:~ //把id_rsa.pub拷貝給A端,複製粘貼id_rsa.pub內容到B端也可
# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys //追加到authorized_keys中
//A端測試
# ssh [B端ip]
//B端測試
# ssh [A端ip]