linux ssh-keygen无密码登录
先确保ssh安装了,master和slave都添加了hadoop用户
第一步,master:
$ ssh-keygen -t dsa -P '' -f /home/hadoop/.ssh/id_dsa
$ cd .ssh/
$ cat id_dsa.pub >> authorized_keys
$ chmod 600 .ssh/authorized_keys
$ ssh master
第二步,slave:
$ mkdir /home/hadoop/.ssh
$ chmod 700 .ssh
第三步,master:
$ scp .ssh/id_dsa.pub hadoop@slave:/home/hadoop/.ssh/
第四步,slave:
$ cd .ssh/
$ cat id_dsa.pub >> authorized_keys
$ chmod 600 authorized_keys
第五步,master:
$ ssh slave
master log:
[hadoop@master ~]$ ssh-keygen -t dsa -P '' -f /home/hadoop/.ssh/id_dsa
Generating public/private dsa key pair.
Created directory '/home/hadoop/.ssh'.
Your identification has been saved in /home/hadoop/.ssh/id_dsa.
Your public key has been saved in /home/hadoop/.ssh/id_dsa.pub.
The key fingerprint is:
1c:96:85:88:c2:c5:39:6a:9b:f9:1b:ee:74:da:ff:c5 [email protected]
[hadoop@master ~]$ cd .ssh/
[hadoop@master .ssh]$ ls
id_dsa id_dsa.pub
[hadoop@master .ssh]$ cat id_dsa.pub >> authorized_keys
[hadoop@master .ssh]$ ll
total 24
-rw-rw-r-- 1 hadoop hadoop 610 Aug 22 02:54 authorized_keys
-rw------- 1 hadoop hadoop 668 Aug 22 02:53 id_dsa
-rw-r--r-- 1 hadoop hadoop 610 Aug 22 02:53 id_dsa.pub
[hadoop@master .ssh]$ ssh master
The authenticity of host 'master (192.168.2.128)' can't be established.
RSA key fingerprint is 9f:82:3d:8e:ee:00:a4:9e:3f:95:7d:47:2a:2f:d5:0b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master,192.168.2.128' (RSA) to the list of known hosts.
hadoop@master's password:
Last login: Thu Aug 22 02:50:22 2013 from slave
[hadoop@master ~]$ ssh master
hadoop@master's password:
Last login: Thu Aug 22 02:54:45 2013 from master
[hadoop@master ~]$ chmod 600 .ssh/authorized_keys
[hadoop@master ~]$ ssh master
Last login: Thu Aug 22 02:55:05 2013 from master
执行下面的slave log,再接着执行
[hadoop@master ~]$ scp .ssh/id_dsa.pub hadoop@slave:/home/hadoop/.ssh/
The authenticity of host 'slave (192.168.2.130)' can't be established.
RSA key fingerprint is 4e:6f:2f:00:99:2f:5a:c4:2a:b3:b8:8f:76:e8:ce:47.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,192.168.2.130' (RSA) to the list of known hosts.
hadoop@slave's password:
id_dsa.pub 100% 610 0.6KB/s 00:00
[hadoop@master ~]$ ssh slave
Last login: Thu Aug 22 02:50:31 2013 from master
slave log:
[hadoop@slave ~]$ mkdir /home/hadoop/.ssh
[hadoop@slave ~]$ chmod 700 .ssh
[hadoop@slave ~]$ ll
total 0
[hadoop@slave ~]$ ll
total 0
[hadoop@slave ~]$ cd .ssh/
[hadoop@slave .ssh]$ ll
total 8
-rw-r--r-- 1 hadoop hadoop 610 Aug 22 02:59 id_dsa.pub
[hadoop@slave .ssh]$ cat id_dsa.pub >> authorized_keys
[hadoop@slave .ssh]$ ll
total 16
-rw-rw-r-- 1 hadoop hadoop 610 Aug 22 03:00 authorized_keys
-rw-r--r-- 1 hadoop hadoop 610 Aug 22 02:59 id_dsa.pub
[hadoop@slave .ssh]$ chmod 600 authorized_keys
[hadoop@slave .ssh]$ ll
total 16
-rw------- 1 hadoop hadoop 610 Aug 22 03:00 authorized_keys
-rw-r--r-- 1 hadoop hadoop 610 Aug 22 02:59 id_dsa.pub