一、双机互信实现背景
平时我们ssh一台机器的时候会要求输入密码,如果经常ssh某台机器,每次输入密码会比较麻烦,而且有些软件会要求机器之间添加互信,下面有很快捷的方法实现双机互信。
我们准备两台虚拟机
192.168.50.131 masterserver
192.168.50.132 redhatclient
其中redhatclient与masterserver需要实现互信,我们现在redhatclient上操作。
二、实现步骤
1.生成密匙
[root@redhatclient ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/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:
28:05:b8:eb:b5:7a:96:c1:d4:f5:03:5f:a2:d6:d0:d4 root@redhatclient
The key's randomart image is:
+--[ RSA 2048]----+
| .. o.. |
| . . + o E |
| . ... B o |
| . ....o = |
| +. ..S . |
| . +. |
| . . + |
| . = |
| .+ |
+-----------------+
[root@redhatclient ~]#
生成的密匙存放在home目录下面的.ssh文件夹中
[root@redhatclient ~]# cd ~
[root@redhatclient ~]# cd .ssh
[root@redhatclient .ssh]# ls
id_rsa id_rsa.pub
[root@redhatclient .ssh]#
其中,我们需要将id_rsa.pub中的内容发送到需要添加互信的系统中。
2.发送密匙
[root@redhatclient .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.50.131
The authenticity of host '192.168.50.131 (192.168.50.131)' can't be established.
RSA key fingerprint is 6c:02:9d:01:cc: