各个主机均执行以下操作:
## 生成密钥对
ssh-keygen -t rsa ## 一路回车即可
## 进入.ssh目录,如果目录不存在则创建
cd ~/.ssh
## 将公钥导入至authorized_keys
cat id_rsa.pub >> authorized_keys
## 修改文件权限
chmod 700 ~/.ssh
chmod 600 authorized_keys
## 配置主从互相免密登陆
[root@node1 ~]# cat ~/.ssh/id_rsa.pub | ssh root@node2.ambari.com 'cat - >> ~/.ssh/authorized_keys'
[root@node1 ~]# cat ~/.ssh/id_rsa.pub | ssh root@node3.ambari.com 'cat - >> ~/.ssh/authorized_keys'
ssh node2.ambari.com
ssh node3.ambari.com # 验证主机点是否可以免密登陆从节点,执行exit命令退出即可。
多主机免密钥可参考:
https://mp.weixin.qq.com/s?__biz=MzU3MTc1NzU0Mg==&mid=2247483660&idx=1&sn=7b10b29eea5932e48a8dccfcbb6867b7&chksm=fcda0785cbad8e93d38bb81633cdb6372333ab9ff27f2d85c8148336c02abd543d268a86b5c0&scene=21#wechat_redirect
快速配置:
1、ssh-keygen
2、ssh-copy-id -i .ssh/id_rsa.pub node1