SSH无密登陆配置
1. 配置SSH
基本语法
ssh 另一台电脑的ip 地址
即可登陆到另外一台设备上
[root@hadoop05 hadoop-2.5.0-cdh5.3.6]# ssh hadoop03
The authenticity of host 'hadoop03 (192.168.235.130)' can't be established.
RSA key fingerprint is 41:4e:79:96:35:e3:78:6b:0b:38:da:23:66:f7:d6:85.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop03,192.168.235.130' (RSA) to the list of known hosts.
root@hadoop03's password:
Last login: Wed May 6 10:24:06 2020 from 192.168.235.1
[root@hadoop03 ~]# hostname
hadoop03
exit退出
[root@hadoop03 ~]# exit
logout
Connection to hadoop03 closed.
2. 无密钥登陆配置
2.1 原理
2.2生成公钥和私钥(在hadoop03上进行的)
[root@hadoop03 .ssh]# ssh-keygen -t rsa
回车之后,再连续三次回车即可
查看当前列表,此时已出现公钥和私钥
[root@hadoop03 .ssh]# ll
总用量 12
-rw-------. 1 root root 1675 5月 6 15:09 id_rsa
-rw-r--r--. 1 root root 395 5月 6 15:09 id_rsa.pub
-rw-r--r--. 1 root root 812 5月 6 10:38 known_hosts
2.3将公钥拷贝到要免密登录的目标机器上(拷贝到hadoop04和hadoop05)
首先从hadoop03拷贝到hadoop04上
[root@hadoop03 .ssh]# ssh-copy-id hadoop04
此时hadoop04的.ssh文件夹中就会出现
hadoop03的公钥
[root@hadoop04 .ssh]# ll
总用量 8
-rw-------. 1 root root 395 5月 6 15:18 authorized_keys
-rw-r--r--. 1 root root 406 5月 6 09:02 known_hosts
同上,再拷贝到hadoop05上
[root@hadoop03 .ssh]# ssh-copy-id hadoop05
此时hadoop05的.ssh文件夹中就会出现
hadoop03的公钥
[root@hadoop05 .ssh]# ll
总用量 8
-rw-------. 1 root root 395 5月 6 15:24 authorized_keys
-rw-r--r--. 1 root root 812 5月 6 14:42 known_hosts
此时就可以从hadoop03端无密登陆到hadoop04或hadoop05上
[root@hadoop03 .ssh]# ssh hadoop04
Last login: Wed May 6 08:34:51 2020 from 192.168.235.1
还要分别在hadoop04、hadoop05端生成密钥对,并且分别拷贝到其余两个节点上