分别有Hadoop102,Hadoop103,Hadoop104三台Centos7的操作系统
Hadoop102:
[zhenghui@hadoop102 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zhenghui/.ssh/id_rsa):
Created directory '/home/zhenghui/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zhenghui/.ssh/id_rsa.
Your public key has been saved in /home/zhenghui/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:29vGJddzp5yeJWuDi7orqB/lxqof1/aMQ3r8VE07ULw zhenghui@hadoop102
The key's randomart image is:
+---[RSA 2048]----+
| .. |
| .. |
| . .. |
| +E. |
| . S . +. |
| + ..o .. oo+|
| o.=++ o. *.o=|
| .*o.+= ++ *= |
| o=+ o=**.o++. |
+----[SHA256]-----+
[zhenghui@hadoop102 ~]$
发送密钥到远程主机
测试登陆hadoop2—>hadoop103:
可以看到,现在不用再输入hadoop103的密码
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$ ssh hadoop103
Last login: Wed Jan 29 20:30:39 2020 from hadoop102
[zhenghui@hadoop103 ~]$
[zhenghui@hadoop103 ~]$
[zhenghui@hadoop103 ~]$
hadoop3:
[zhenghui@hadoop103 .ssh]$
[zhenghui@hadoop103 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zhenghui/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zhenghui/.ssh/id_rsa.
Your public key has been saved in /home/zhenghui/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:taM9WYogYn6Xx7yBTmmmbVS098WlwLKAqcdNHViWg/8 zhenghui@hadoop103
The key's randomart image is:
+---[RSA 2048]----+
| o =++ |
| o *.= o .|
| o + +.+ o o |
| . o +.+. + |
| o ....S.oo.. |
| o . ..B + =E |
| . ..O B = |
| . O.. o . |
| ..o . |
+----[SHA256]-----+
[zhenghui@hadoop103 .ssh]$
[zhenghui@hadoop103 .ssh]$ ssh-copy-id hadoop102
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/zhenghui/.ssh/id_rsa.pub"
The authenticity of host 'hadoop102 (192.168.1.102)' can't be established.
ECDSA key fingerprint is SHA256:N+tX6TsiuOf5DYG8Aeir/n49gbUnExGpa8RYReNJsxI.
ECDSA key fingerprint is MD5:5b:8d:dd:d2:74:4a:84:18:4b:69:b7:62:9b:4c:d0:38.
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: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
zhenghui@hadoop102's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'hadoop102'"
and check to make sure that only the key(s) you wanted were added.
直接使用脚本
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$ rm -r known_hosts
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$ ll
total 12
-rw------- 1 zhenghui zhenghui 800 Jan 29 20:37 authorized_keys
-rw------- 1 zhenghui zhenghui 1675 Jan 29 20:20 id_rsa
-rw-r--r-- 1 zhenghui zhenghui 400 Jan 29 20:20 id_rsa.pub
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$
[zhenghui@hadoop102 .ssh]$ cop
coproc copypath
[zhenghui@hadoop102 .ssh]$ cd ..
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$ copypath .ssh
count=1
fname=.ssh
pdir=/home/zhenghui
-------------hadoop102-------------
The authenticity of host 'hadoop102 (192.168.1.102)' can't be established.
ECDSA key fingerprint is SHA256:N+tX6TsiuOf5DYG8Aeir/n49gbUnExGpa8RYReNJsxI.
ECDSA key fingerprint is MD5:5b:8d:dd:d2:74:4a:84:18:4b:69:b7:62:9b:4c:d0:38.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop102,192.168.1.102' (ECDSA) to the list of known hosts.
sending incremental file list
sent 179 bytes received 17 bytes 78.40 bytes/sec
total size is 3,060 speedup is 15.61
-------------hadoop103-------------
The authenticity of host 'hadoop103 (192.168.1.103)' can't be established.
ECDSA key fingerprint is SHA256:0unzF7FySiDRZPy1t8Jhclz4Qpjc1VTxqdDR1fIwKw4.
ECDSA key fingerprint is MD5:54:17:89:2e:c4:b6:81:12:f7:a7:2b:60:b6:ea:9e:c3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop103,192.168.1.103' (ECDSA) to the list of known hosts.
sending incremental file list
.ssh/
.ssh/authorized_keys
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/known_hosts
sent 3,208 bytes received 132 bytes 1,336.00 bytes/sec
total size is 3,245 speedup is 0.97
-------------hadoop104-------------
The authenticity of host 'hadoop104 (192.168.1.104)' can't be established.
ECDSA key fingerprint is SHA256:N+tX6TsiuOf5DYG8Aeir/n49gbUnExGpa8RYReNJsxI.
ECDSA key fingerprint is MD5:5b:8d:dd:d2:74:4a:84:18:4b:69:b7:62:9b:4c:d0:38.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop104,192.168.1.104' (ECDSA) to the list of known hosts.
zhenghui@hadoop104's password:
sending incremental file list
.ssh/
.ssh/authorized_keys
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/known_hosts
sent 3,789 bytes received 96 bytes 863.33 bytes/sec
total size is 3,430 speedup is 0.88
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$ ssh hadoop103
Last login: Wed Jan 29 20:38:00 2020 from hadoop102
[zhenghui@hadoop103 ~]$ exit
logout
Connection to hadoop103 closed.
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$ ssh hadoop104
Last login: Wed Jan 29 19:57:49 2020 from 192.168.1.109
[zhenghui@hadoop104 ~]$ exit
logout
Connection to hadoop104 closed.
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$ ssh hadoop102
Last login: Wed Jan 29 20:38:04 2020 from hadoop102
[zhenghui@hadoop102 ~]$ exit
logout
Connection to hadoop102 closed.
[zhenghui@hadoop102 ~]$
[zhenghui@hadoop102 ~]$