- 配置ssh
(1)基本语法
ssh另一台电脑的ip地址
(2)ssh连接时出现Host key verification failed的解决方法
[hadoop@master opt] $ ssh 192.168.1.103
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is cf:1e:de:d7:d0:4c:2d:98:60:b4:fd:ae:b1:2d:ad:06.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
(3)解决方案如下:直接输入yes
2. 无密钥配置
(1)免密登录原理,如图2-40所示
图2-40 免密登陆原理
(2)生成公钥和私钥:
[hadoop@master.ssh]$ ssh-keygen -t rsa
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
(3)将公钥拷贝到要免密登录的目标机器上
[hadoop@master.ssh]$ ssh-copy-id hadoop102
[hadoop@master.ssh]$ ssh-copy-id hadoop103
[hadoop@master.ssh]$ ssh-copy-id hadoop104
注意:
还需要在master上采用root账号,配置一下无密登录到master、slave1、slave2;
还需要在slave1上采用hadoop账号配置一下无密登录到master、slave1、slave2服务器上。
3. .ssh文件夹下(~/.ssh)的文件功能解释
表2-4
known_hosts | 记录ssh访问过计算机的公钥(public key) |
d_rsa | 生成的私钥 |
id_rsa.pub | 生成的公钥 |
authorized_keys | 存放授权过得无密登录服务器公钥 |
以下为具体操作截图:
生成公钥和私钥
[hadoop@master hadoop]$ ssh-keygen -t rsa //生成公钥和私钥
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:snqLDZ8bF00TDLq3JBbkNWR/op2anBinh4CPkvyCTak hadoop@master
The key's randomart image is:
+---[RSA 2048]----+
| ..*o. |
| o + o.. |
| + = . |
| . o = = |
| ... * S + |
|..oo o & * |
|+=. o * O |
|Eoo *.= |
| ..o.*o |
+----[SHA256]-----+
将公钥拷贝到要免密登录的目标机器上
[hadoop@master hadoop]$ ssh-copy-id slave1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.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
hadoop@slave1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'slave1'"
and check to make sure that only the key(s) you wanted were added.
[hadoop@master hadoop]$ ssh-copy-id slave2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.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
hadoop@slave2's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'slave2'"
and check to make sure that only the key(s) you wanted were added.