//单向免密登陆
//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]