Hadoop架设过程中实现普通用户权限下SSH无密码登录

来源:互联网 发布:网络机顶盒看莆田卫视 编辑:程序博客网 时间:2024/06/04 18:20

Hadoop架设过程中实现普通用户权限下SSH无密码登录

from http://snowfigure.diandian.com/post/2012-09-23/40038545536

1
2
3
4
5
6
7
8
9
10
11
12
13
14
配置信息
                                                      
Master  Ubuntu 11.10
Slave   Red hat 9
虚拟机    Vmware workstation
ip段设置
        Master    192.168.68.128
        Slave01   192.168.68.129
            ...
        Slave05    192.168.68.133
统一用户名
    hadoop
统一密码
    hadoop123

按照常规流程,Slave机器全是用命令行(文本界面,非图形界面)模式,只有Master使用Ubuntu的图形界面


首先在Master机器上设置:

1、修改每台机器的/etc/hosts文件

Master机器修改结果如下

1
2
3
4
5
6
7
8
9
10
11
12
13
127.0.0.1   localhost
192.168.68.128  Master
192.168.68.129  Slave01
192.168.68.130  Slave02
192.168.68.131  Slave03
192.168.68.132  Slave04
192.168.68.133  Slave05 
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

 

Slave机器修改结果如下

1
2
3
4
5
6
7
8
9
10
11
12
127.0.0.1   localhost
 192.168.68.129  Slave01
 192.168.68.130  Slave02
 192.168.68.131  Slave03
 192.168.68.132  Slave04
 192.168.68.133  Slave05
 # The following lines are desirable for IPv6 capable hosts
 ::1     ip6-localhost ip6-loopback
 fe00::0 ip6-localnet
 ff00::0 ip6-mcastprefix
 ff02::1 ip6-allnodes
 ff02::2 ip6-allrouters

 

2、在所有机器(Master和Slave上面)建立统一的用户

1
2
3
4
5
root权限登录
                                          
useradd hadoop     或者 useradd -m hadoop
passwd hadoop
然后输入两次密码确认

 

3、在所有机器的/home/hadoop/目录下建立 .ssh文件夹

1
mkdir .ssh

4、在Master机器上开始生成密钥对

1
2
3
ssh-keygen -t rsa
                                     
然后一路回车即可

 

5、切换到.ssh目录

1
2
3
4
5
6
7
8
9
hadoop@ubuntu:~$ cd /home/hadoop/.ssh
hadoop@ubuntu:~/.ssh$ ll
total 24
drwxrwxr-x  2 hadoop hadoop 4096 2012-09-23 01:03 ./
drwxr-xr-x 24 hadoop hadoop 4096 2012-09-23 01:10 ../
-rw-r--r--  1 hadoop hadoop  395 2012-09-23 01:03 authorized_keys
-rw-------  1 hadoop hadoop 1679 2012-09-23 01:02 id_rsa
-rw-r--r--  1 hadoop hadoop  395 2012-09-23 01:02 id_rsa.pub
-rw-r--r--  1 hadoop hadoop  762 2012-09-23 01:31 known_hosts

 

执行

1
cp id_rsa.pub authorized_keys

然后对于在Master上面分别把authorized_keys文件复制到每一个Slave机器的/home/hadoop/.ssh/文件下面


1
2
3
4
5
scp authorized_keys slave01:/home/hadoop/.ssh/
scp authorized_keys slave02:/home/hadoop/.ssh/
scp authorized_keys slave03:/home/hadoop/.ssh/
scp authorized_keys slave04:/home/hadoop/.ssh/
scp authorized_keys slave05:/home/hadoop/.ssh/


6、修改.ssh目录的权限以及authorized_keys 的权限

1
2
3
4
5
[root@slave01 .ssh]# ls -la
 total 12
 drwx------    2 hadoop   hadoop       4096 Sep 23 16:06 .
 drwx------    3 hadoop   hadoop       4096 Sep 23 16:07 ..
 -rw-r--r--    1 hadoop   hadoop        395 Sep 23 16:06 authorized_keys


修改过程如下:

1
sudo chmod 644 authorized_keys

返回.ssh的上层目录

1
sudo chmod 700 .ssh

 

正常情况下到这个地方就可以SSH无密码登录了,但是天不如人愿,他就是不行。

 

好吧我们继续修改

 

到Slave机器上(每一个都要进行这些操作的)

1
2
3
4
5
6
7
8
9
10
11
12
[root@slave01 .ssh]# cd /etc/ssh
 [root@slave01 ssh]# ll
 total 124
 -rw-------    1 root     root        88039 Feb 15  2003 moduli
 -rw-r--r--    1 root     root         1167 Sep 23 16:30 ssh_config
 -rw-------    1 root     root         2472 Sep 23 16:31 sshd_config
 -rw-------    1 root     root          668 Sep 23 15:34 ssh_host_dsa_key
 -rw-r--r--    1 root     root          590 Sep 23 15:34 ssh_host_dsa_key.pub
 -rw-------    1 root     root          515 Sep 23 15:34 ssh_host_key
 -rw-r--r--    1 root     root          319 Sep 23 15:34 ssh_host_key.pub
 -rw-------    1 root     root          887 Sep 23 15:34 ssh_host_rsa_key
 -rw-r--r--    1 root     root          210 Sep 23 15:34 ssh_host_rsa_key.pub

修改sshd_config

1
[root@slave01 ssh]# vi sshd_config

修改

1
2
#PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

(去掉#,并修改)

1
2
PasswordAuthentication no
#PermitEmptyPasswords no

这样就可以无密码登录了

1
2
hadoop@ubuntu:~/.ssh$ ssh Slave01
[hadoop@slave01 hadoop]$

 


原创粉丝点击