学习hadoop的时候启动hadoop集群需要免密登录,手动台蛋疼了,
所以总结了下,root用户免密和普通用户免密两种方法.
root用户
我有如下三台Linux机器
192.168.13.102 centos102
192.168.13.103 centos103
192.168.13.105 centos105
1.修改hosts文件vi /etc/hosts如下:
192.168.13.102 centos102
192.168.13.103 centos103
192.168.13.105 centos105
2.在/root(即~)下看有没有.ssh文件夹,ls -a查看,如果没有则创建mkdir .ssh
3.进入.ssh文件夹,cd /root/.ssh
4.执行ssh-keygen -t rsa,三次回车
5.执行cat id_rsa.pub >> authorized_keys
6.其他两台机器103 105都执行1~4步骤,
7.centos103,centos105分别执行ssh-copy-id -i centos102 这行命令的意思是登录centos102将公钥拷贝到centos102中的authorized_keys中
8.回到centos102,执行more /root/.ssh/authorized_keys能看到如下则成功
9.修改authorized_keys权限为600 chmod 600 authorized_keys
10.将授权文件分别拷贝到centos103,centos105
scp /root/.ssh/authorized_keys centos103:/root/.ssh/
scp /root/.ssh/authorized_keys centos105:/root/.ssh/
11.ssh centos103去免密登录试试吧,exit退出.
非root用户
1.vi /etc/ssh/sshd_config确保如下两项是放开的(即去掉前面的#)
AuthorizedKeysFile .ssh/authorized_keys
PubkeyAuthentication yes
2.修改hosts文件vi /etc/hosts如下:
192.168.13.102 centos102
192.168.13.103 centos103
192.168.13.105 centos105
3.cd ~,看有没有.ssh文件夹,ls -a查看,如果没有则创建mkdir .ssh
4.进入.ssh文件夹,~/.ssh
5.执行ssh-keygen -t rsa,三次回车
6.执行cat id_rsa.pub >> authorized_keys
7.centos103,centos105分别执行1~5步骤
8.centos103执行
scp ~/.ssh/id_rsa.pub hadoop@centos102:~/.ssh/centos103.id_rsa.pub
期间会要求输入centos102的hadoop账号的密码,输入后传输完成,在node0的/home/hadoop/.ssh目录下,多了个名为 centos103.id_rsa.pub的文件;
9.centos105执行
scp ~/.ssh/id_rsa.pub hadoop@centos102:~/.ssh/centos105.id_rsa.pub
10.centos103,centos105分别把centosxxx.id_rsa.pub文件加到authorized_keys中 cat centosxxx.id_rsa.pub >> authorized_keys
11.在102上将authorized_keys分发到其他机器
scp ~/.ssh/authorized_keys hadoop@centos103:~/.ssh/
scp ~/.ssh/authorized_keys hadoop@centos103:~/.ssh/
12.三台机器都执行文件授权
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
13.ssh centos103去免密登录试试吧,exit退出.