![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
免密码ssh设置 现在确认能否不输入口令就用ssh登录localhost: $ ssh localhost 如果不输入口令就无法用ssh登陆localhost,执行下面的命令: 1. 并修改hosts映射: 添加:(配置三台机器hosts,保证可以互相访问) $ vi /etc/hosts 127.0.0.1 localhost.localdomain localhost 192.168.126.10 master.localdomain master 192.168.126.20 slave1.localdomain slave1 192.168.126.30 slave2.localdomain slave2 2. 生成三台机器的密钥和公钥 $ ssh-keygen -t rsa -f ~/.ssh/id_rsa #生成秘钥和公钥 $ cat ~.ssh/id_rsa.pub >> ~/.ssh/authorized_keys //把当前主机的公钥添加到authorized_keys文件 $ scp .ssh/id_rsa.pub root@192.168.126.10:/home/hadoop/.ssh/authorized_keys_slave1 //复制slave1公钥添加到authorized_keys_slave1文件 $ scp .ssh/id_rsa.pub root@192.168.126.10:/home/hadoop/.ssh/authorized_keys_slave2 //复制slave2公钥添加到authorized_keys_slave2文件 3.把slave1和slave2的公钥追加到authorized_keys $ cat /home/hadoop/.ssh/authorized_keys_slave1 >> /home/hadoop/.ssh/authorized_keys $ cat /home/hadoop/.ssh/authorized_keys_slave2 >> /home/hadoop/.ssh/authorized_keys master配置 ################master################# $ cat id_rsa.pub >> authorized_keys $ cat authorized_keys_slave1 >> authorized_keys $ cat authorized_keys_slave2 >> authorized_keys $ chmod 644 authorized_keys//修改权限 ###################################### 4.把主机的公共密钥复制到slave1和slvae2 $ scp id_rsa.pub root@192.168.126.20:/home/hadoop/.ssh/authorized_keys_master $ scp id_rsa.pub root@192.168.126.30:/home/hadoop/.ssh/authorized_keys_master slave1配置 ##################slave1##################### cat id_rsa.pub >> authorized_keys cat authorized_keys_master >> authorized_keys chmod 644 authorized_keys ###################################### slave2配置 ##################slave2##################### cat id_rsa.pub >> authorized_keys cat authorized_keys_master >> authorized_keys chmod 644 authorized_keys #######################################
最后测试:
master主机访问slave1和slave2:
ssh 192.168.126.20 //回车,如果切换到slave1,则访问成功。slave3同理。