1.分别安装SSH服务端和客户端
yum install openssh* -y
2.创建密钥对
[root@A /]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?
3.将公钥文件发送给对端
[root@A .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.17.135
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
The authenticity of host '192.168.17.135 (192.168.17.135)' can't be established.
ECDSA key fingerprint is SHA256:Vx7YJMJHJvsQYQP9wqLRJkTumT5U6M2P7d06k4W/odU.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
(if you think this is a mistake, you may want to use -f option)
验证结果
[root@A .ssh]# ssh root@192.168.17.135
Last login: Thu Nov 5 17:16:14 2020 from 192.168.17.1
[root@B ~]# //成功由Assh到B
在B上重复A的操作最终实现免密登录效果