无密钥配置

生成公钥和私钥

[fygod@hadoop102 .ssh]$ pwd
/home/fygod/.ssh
[fygod@hadoop102 .ssh]$ ssh-keygen -t rsa
[fygod@hadoop102 .ssh]$ ll
总用量 12
-rw-------. 1 fygod fygod 1679 8月  22 09:13 id_rsa
-rw-r--r--. 1 fygod fygod  397 8月  22 09:13 id_rsa.pub
-rw-r--r--. 1 fygod fygod  558 8月  21 18:33 known_hosts

id_rsa.pub即公钥,将hadoop102的公钥分别复制一份给hadoop103hadoop104
使用一次ssh需要密码和其他主机取得联系

[fygod@hadoop102 .ssh]$ ssh-copy-id hadoop103
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/fygod/.ssh/id_rsa.pub"
/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
fygod@hadoop103's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hadoop103'"
and check to make sure that only the key(s) you wanted were added.

以后就不用再输密码了

[fygod@hadoop102 .ssh]$ ssh hadoop103
Last login: Sun Aug 22 09:09:28 2021 from 192.168.10.1
[fygod@hadoop103 ~]$

别忘了,就算ssh自己也要输入一次密码;此时,在hadoop103.ssh目录下就出现了authorized_keys文件

[fygod@hadoop103 .ssh]$ cat authorized_keys 
ssh-rsa AAAAB3Nza....

 fygod@hadoop102
//这就说明对于103,102已经被授权

一顿操作之后

[fygod@hadoop103 .ssh]$ ssh hadoop104
Last login: Sun Aug 22 09:42:10 2021 from hadoop103
[fygod@hadoop104 ~]$ exit
登出
Connection to hadoop104 closed.
[fygod@hadoop103 .ssh]$ ssh hadoop102
Last login: Sun Aug 22 09:42:26 2021 from hadoop103
[fygod@hadoop102 ~]$ ssh hadoop103
Last login: Sun Aug 22 09:28:33 2021 from hadoop102
[fygod@hadoop103 ~]$ ssh hadoop104
Last login: Sun Aug 22 09:46:29 2021 from hadoop103
[fygod@hadoop104 ~]$