1.本机环境
主机名 | ip |
hadoop001 | 192.168.137.200 |
hadoop002 | 192.168.137.201 |
hadoop003 | 192.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