SSH无密登录配置
SSH无密登录配置
一.配置ssh
(1)基本语法
ssh另一台电脑的ip地址
(2)ssh连接时出现Host key verification failed的解决方法
[atguigu@hadoop102 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🇩🇪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
二.无密钥配置
(1)免密登录原理,如图2-40所示
图2-40 免密登陆原理
(2)生成公钥和私钥:
[atguigu@hadoop102 hadoop-2.7.2]$ cd ~
[atguigu@hadoop102 ~]$ ls -al
[atguigu@hadoop102 ~]$ cd .ssh/
[atguigu@hadoop102 .ssh]$ cat known_hosts
访问过的主机记录:
[atguigu@hadoop102 .ssh]$ ssh-keygen -t rsa
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
(3)将公钥拷贝到要免密登录的目标机器上
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop102
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop103
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop104
(4)测试:
注意:
还需要在hadoop102上采用root账号,配置一下无密登录到hadoop102、hadoop103、hadoop104,因为102上有hdfs的namenode节点需要对其他节点通讯;
还需要在hadoop103上采用atguigu账号配置一下无密登录到hadoop102、hadoop103、hadoop104服务器上,应为103上有yarn的ResourceManager节点需要对其他节点通讯。
三. .ssh文件夹下(~/.ssh)的文件功能解释
表2-4
known_hosts | 记录ssh访问过计算机的公钥(public key) |
---|---|
id_rsa | 生成的私钥 |
id_rsa.pub | 生成的公钥 |
authorized_keys |