[Hadoop cluster building] ssh password free login setting
There are three hosts, their IP addresses and roles in the cluster are as follows:
172.17.0.2 //master 172.17.0.3 //slave1 172.17.0.4 //slave2
Now you want to make the two of them able to log in through ssh, the steps are as follows:
Create public key and configure accordingly
Perform the following 4 steps on 3 machines:
(1) create a key file:
root@540d1f9fc209:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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: SHA256:dxqbt5mrIHOrq8gbyz0R9FeqlLVAoIp/zQHfD7RyPs4 root@540d1f9fc209 The key's randomart image is: +---[RSA 2048]----+ | .o. | | .. . . . | | .... +.+ | |.. .o+o+. | |o o+oS o . | | . .o.= + * | | o ..= = = . | | o *. * + . + | | *.ooooE ..=. | +----[SHA256]-----+ root@540d1f9fc209:~# ll total 108 drwx------ 1 root root 4096 Nov 7 09:16 ./ drwxr-xr-x 1 root root 4096 Nov 7 07:18 ../ -rw------- 1 root root 54424 Nov 5 08:47 .bash_history -rw-r--r-- 1 root root 3560 Sep 21 12:44 .bashrc drwx------ 2 root root 4096 Sep 21 07:22 .cache/ drwxr-xr-x 2 root root 4096 Sep 21 12:10 .oracle_jre_usage/ -rw-r--r-- 1 root root 148 Aug 17 2015 .profile drwx------ 2 root root 4096 Nov 7 09:16 .ssh/ -rw------- 1 root root 18886 Nov 7 09:00 .viminfo -rw-r--r-- 1 root root 170 Oct 13 06:59 .wget-hsts root@540d1f9fc209:~# cd .ssh/ root@540d1f9fc209:~/.ssh# ll total 16 drwx------ 2 root root 4096 Nov 7 09:16 ./ drwx------ 1 root root 4096 Nov 7 09:16 ../ -rw------- 1 root root 1675 Nov 7 09:16 id_rsa -rw-r--r-- 1 root root 399 Nov 7 09:16 id_rsa.pub
(2) modify the / etc/ssh/ssh_config file under the master, and add the following two lines:
StrictHostKeyChecking no UserKnownHostsFile /dev/null
(3) run the following command to restart the ssh service:
service ssh restart
(4) in the ~ /. ssh directory, create the automated_keys file, and append the id_rsa.pub to the authorized_keys:
root@540d1f9fc209:~/.ssh# touch authorized_keys root@540d1f9fc209:~/.ssh# chmod 600 authorized_keys root@540d1f9fc209:~/.ssh# cat id_rsa.pub >> authorized_keys
Copy public key
(1) copy the id_rsa.pub of master to slave1 and slave2 respectively, and append it to ~ /. ssh/authorized_keys of slave1 and slave2 respectively;
(2) copy the id_rsa.pub of slave1 to master and slave2 respectively, and add it to ~ /. ssh/authorized_keys of master and slave2 respectively;
(3) copy the id_rsa.pub of slave2 to master and slave1 respectively, and append it to ~ /. ssh/authorized_keys of master and slave1 respectively.
Restart ssh service
Restart the ssh service on each machine:
service ssh restart
test
For a simple test, log in to slave 2 from the master
root@540d1f9fc209:~/.ssh# ssh 172.17.0.4 Warning: Permanently added '172.17.0.4' (ECDSA) to the list of known hosts. Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-133-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Wed Nov 7 10:28:29 2018 from 172.17.0.2 root@56ab96e7e138:~#