一、安装SSH:
sudo apt install ssh
二、生成公钥和私钥:
hadoop@master:/$ ssh-keygen -t rsa -P ""
Generating public/private rsa key pair.
Enter file in which to save the key (/home/slave1/.ssh/id_rsa):
Created directory '/home/slave1/.ssh'.
Your identification has been saved in /home/slave1/.ssh/id_rsa
Your public key has been saved in /home/slave1/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:C491RjetPChq356JFiBwHDBlsgh/8k46RpoF11NtGaU slave1@slave1
The key's randomart image is:
+---[RSA 3072]----+
|. +++....+. |
|.o.*o. +. . |
|o =o+ .E . o . |
| o +... . + o |
| o o...S + + |
| = + *.= . |
|o + . + o. |
| . . . ..o o |
| .o.= |
+----[SHA256]-----+
三、查看生成的文件:
hadoop@master:/$ cd ~/.ssh/
hadoop@master:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
四、将公钥追加到authorized_keys中,用来保存用户登录SSH客户端的公钥内容:
hadoop@master:~/.ssh$ cat id_rsa.pub >> authorized_keys
hadoop@master:~/.ssh$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
五、将authorized_keys文件发送给其他机器
hadoop@master:~/.ssh$ scp authorized_keys slave1@slave1:~/.ssh/
slave1@slave1's password:
authorized_keys 100% 567 54.0KB/s
六、SSH免密登录其他机器:
hadoop@master:~/.ssh$ ssh slave1@slave1
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-52-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
241 updates can be installed immediately.
104 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Your Hardware Enablement Stack (HWE) is supported until April 2025.
slave1@slave1:~$