配置多台虚拟机之间的SSH信任

1.本机环境
主机名ip
hadoop001192.168.137.200
hadoop002192.168.137.201
hadoop003192.168.137.202
2. 3台机器执行命令ssh-keygen
[root@hadoop001 ~]# ssh-keygen
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:
3d:e9:3c:96:d8:ea:ac:dc:92:ab:5e:6a:93:ea:8a:20 root@hadoop001
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|         . .     |
|        S +      |
|         = o     |
|E    .... B      |
|+   ++oo o .     |
|ooo++o+==        |
+-----------------+

[root@hadoop001 ~]# cat /root/.ssh/id_rsa.pub>> /root/.ssh/authorized_keys
  • hadoop002 hadoop003传输id_rsa.pub文件到hadoop001

hadoop002机器

[hadoop@hadoop002 ~]$ su - root
Password: 
[root@hadoop002 ~]#  cat /root/.ssh/id_rsa.pub>> /root/.ssh/authorized_keys

[root@hadoop002 ~]# cd .ssh

[root@hadoop002 .ssh]# ll
total 12
-rw-r--r--. 1 root root  396 Feb 10 12:31 authorized_keys
-rw-------. 1 root root 1675 Feb 10 12:29 id_rsa
-rw-r--r--. 1 root root  396 Feb 10 12:29 id_rsa.pub

[root@hadoop002 .ssh]# scp id_rsa.pub 192.168.137.200:/root/.ssh/id_rsa.pub2
id_rsa.pub                                                      100%  394     0.4KB/s   00:00

hadoop003机器

[hadoop@hadoop003 ~]$ su - root
Password: 
[root@hadoop003 ~]#  cat /root/.ssh/id_rsa.pub>> /root/.ssh/authorized_keys
[root@hadoop003 ~]# cd .ssh
[root@hadoop003 .ssh]# ll
total 16
-rw-------. 1 root root  788 Feb 10 12:08 authorized_keys
-rw-------. 1 root root 1675 Jan 19 13:16 id_rsa
-rw-r--r--. 1 root root  394 Jan 19 13:16 id_rsa.pub

[root@hadoop003 .ssh]# scp id_rsa.pub 192.168.137.200:/root/.ssh/id_rsa.pub3
id_rsa.pub                                                      100%  394     0.4KB/s   00:00 
3.hadoop001机器 合并id_rsa.pub2、id_rsa.pub3到authorized_keys
[root@hadoop001 ~]# cd .ssh

[root@hadoop001 .ssh]# ll
total 20
-rw-------. 1 root root  788 Feb 10 12:07 authorized_keys
-rw-------. 1 root root 1675 Jan 19 13:16 id_rsa
-rw-r--r--. 1 root root  394 Jan 19 13:16 id_rsa.pub
-rw-r--r--. 1 root root  394 Feb 10 12:11 id_rsa.pub2
-rw-r--r--. 1 root root  405 Jan 15 19:34 known_hosts

[root@hadoop001 .ssh]# cat id_rsa.pub2 >> authorized_keys
[root@hadoop001 .ssh]# cat id_rsa.pub3 >> authorized_keys
4.将authorized_keys分发到hadoop002、hadoop003机器
[root@hadoop001 .ssh]# scp authorized_keys 192.168.137.201:/root/.ssh/
The authenticity of host '192.168.137.201 (192.168.137.201)' can't be established.
RSA key fingerprint is 9d:97:35:c5:62:24:65:1a:7f:23:44:12:72:25:86:41.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.137.201' (RSA) to the list of known hosts.
authorized_keys                                                 100% 1576     1.5KB/s   00:00    
[root@hadoop001 .ssh]# scp authorized_keys 192.168.137.202:/root/.ssh/
The authenticity of host '192.168.137.202 (192.168.137.202)' can't be established.
RSA key fingerprint is 9d:97:35:c5:62:24:65:1a:7f:23:44:12:72:25:86:41.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.137.202' (RSA) to the list of known hosts.
authorized_keys 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值