1.实验环境
操作系统 linux 5.5
host1 ip 192.168.99.11
host2 ip 192.168.99.12
2.实验部署
2.1
host1#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
Enter passphrase (empty for no passphrase):直接回车
Enter same passphrase again:直接回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 root@host1
2.2在/root/.ssh/路径下会生成id_rsa,和id_rsa.pub,其中id_rsa是密钥,id_rsa.pub是公钥;
host1#scp /root/.ssh/id_rsa.pub root@192.168.99.12:/root/ --远程复制刚生成的公钥到host2主机上
2.3在host2使用root账号登陆
host2#cat /root/id_rsa.pub >> /root/.ssh/authorized_keys --将公钥加入认证的主机上
host2#rm -rf /root/id_rsa.pub --删除多余的文件
host2#chmod 400 authorized_keys --修改权限在登录的时候,免费去提供密码
3.测试
在host1上 ssh 192.168.99.12 无密码可直接连接登陆
是不是大功告成了!