安装SSH:
$ sudo apt-get install ssh查看是否生成目录.ssh:
$ ls -al /home/xsj/如果没有,手动创建目录.ssh:
$ mkdir /home/xsj/.ssh生成公、私密钥:
ssh−keygen−tdsa−P”−f /.ssh/iddsa或 ssh-keygen -t rsa将公钥加到用于认证的公钥文件中:
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
或
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys验证是否SSH安装成功:
$ ssh -version免密码登陆:
$ ssh localhost
Linux xsj-virtual-machine 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux
Ubuntu 10.10
如果出现Permission denied。。。。错误,要求重新输入密码。
修改/etc/ssh/sshd_config文件,然后将PermitRootLogin 改为 yes
再通过/etc/ssh/ssh restart 重启ssh
第二种方法:
生成公钥密钥对:
[root@nameNode /]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
98:3c:31:5c:23:21:73:a0:a0:1f:c6:d3:c3:dc:58:32 root@gifer
The key’s randomart image is:
+–[ RSA 2048]—-+
|. E.=.o |
|.o = @ o . |
|. * * = |
| o o o = |
| . = S |
| . |
| |
| |
| |
+—————–+
看到图形输出,表示密钥生成成功,目录下多出两个文件
私钥文件:id_raa
公钥文件:id_rsa.pub
将公钥文件id_rsa.pub内容放到authorized_keys文件中:
cat id_rsa.pub >> authorized_keys
将公钥文件authorized_keys分发到各dataNode节点:
scp authorized_keys root@dataNode:/root/.ssh/
验证ssh无密码登录:
[root@nameNode .ssh]# ssh root@dataNode1
Last login: Sun Sep 21 11:38:05 2014 from 192.168.17.1
看到以上输出,表示配置成功!如果还提示需要输出密码访问,表示配置失败!