生成rsa
ssh-keygen -t rsa
将生成的秘钥发送到其他服务器
ssh-copy-id hadoop1
执行结果
[root@hadoop2 ~]# ssh-copy-id hadoop1 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'hadoop1 (192.168.52.101)' can't be established. ECDSA key fingerprint is SHA256:tmlEUTX/zC4HLJENTTO6X2Kx0ELMHn95iT9c8foctvI. ECDSA key fingerprint is MD5:1a:04:b6:95:d7:2e:ec:a0:50:04:46:9d:2a:73:77:0e. 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 root@hadoop1's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'hadoop1'" and check to make sure that only the key(s) you wanted were added.
将authorized_keys发送到其他服务器的方法:
定位到authorized_keys 存放位置
cd /root/.ssh
scp authorized_keys hadoop1:$PWD
执行结果:
[root@hadoop1 ~]# cd /root/.ssh [root@hadoop1 .ssh]# scp authorized_keys hadoop1:$PWD root@hadoop1's password: authorized_keys