1.切换你要的用户
[root@bgs-5p173-wangwenting ~]$ su hadoop
2.生成密钥,一直按enter键:
[hadoop@bgs-5p173-wangwenting ~]$ ssh-keygen -t rsa
3.将秘钥发送到其他机器上:
[hadoop@bgs-5p173-wangwenting ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@bgs-5p173-wangwenting
[hadoop@bgs-5p173-wangwenting ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@bgs-5p174-wangwenting
[hadoop@bgs-5p173-wangwenting ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@bgs-5p175-wangwenting
4.验证是否免秘钥登录成功:
[hadoop@bgs-5p173-wangwenting ~]$ ssh 172.24.5.173
[hadoop@bgs-5p173-wangwenting ~]$ ssh 172.24.5.174
[hadoop@bgs-5p173-wangwenting ~]$ ssh 172.24.5.175
如果能登录且不用输密码,则172.24.5.173可以免密码登录另外两台机器。
5.同理,如果其他的机器上免秘钥登录,重复上述步骤就可以了。不过你可以写一个shell脚本去执行,每次只要修改一下用户就可以了。
思想是:每台创建一个公钥,然后再.ssh目录下创建一个authorized_keys将每台机器上的公钥拷贝进去,则可以实现免秘钥。