由于配置手册中的免密登陆配置略显复杂,所以找到了一个相对简单的配置方式
1、生成RSA公钥
$ ssh-keygen -t rsa 一直回车生成一对公用密钥
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/beifeng/.ssh/id_rsa):
Created directory '/home/beifeng/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/beifeng/.ssh/id_rsa.
2、
把自己的密钥拷贝给集群中所有机器
在centos001
$ ssh-copy-id centos001
$ ssh-copy-id centos002
$ ssh-copy-id centos003
在centos002
$ ssh-keygen -t rsa
$ ssh-copy-id centos001
$ ssh-copy-id centos002
$ ssh-copy-id centos003
在centos003
$ ssh-keygen -t rsa
$ ssh-copy-id centos001
$ ssh-copy-id centos002
$ ssh-copy-id centos003
3、一般情况下使用RSA就可以了,可是有时还会踩到坑,在已经配置RSA且所有主机可以互访的情况下,ambari仍然提示公钥问题无法链接集群中其他主机
这时候就需要使用DSA了
on host1:
rm -rf /root/.ssh
ssh-keygen -t dsa
cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
scp /root/.ssh/id_dsa.pub host2:/root/
scp /root/.ssh/id_dsa.pub host3:/root/
on host2:
rm -rf /root/.ssh
ssh-keygen -t dsa
cat /root/id_dsa.pub >> /root/.ssh/authorized_keys
on host3:
rm -rf /root/.ssh
ssh-keygen -t dsa
cat /root/id_dsa.pub >> /root/.ssh/authorized_keys
host1:/root/.ssh/id_dsa This's the file which you need.
之后在ambari中输入DSA公钥,便不会报错了