deven@node1 ~]$ cd

[deven@node1 ~]$ mkdir .ssh (centos6.0无需)

[deven@node1 ~]$ chmod 700 .ssh (centos6.0无需)

[deven@node1 ~]$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/deven/.ssh/id_rsa): (回车)

Enter passphrase (empty for no passphrase): (回车)

Enter same passphrase again:(回车)

Your identification has been saved in /home/deven/.ssh/id_rsa.

Your public key has been saved in /home/deven/.ssh/id_rsa.pub.

The key fingerprint is:

89:56:d6:4a:b2:6c:4a:05:86:ae:cd:7d:80:dd:3c:f1 deven@node1

中间过程直接3个回车。在~/.ssh/目录下,生成了两个文件:id_rsa(私钥文件放在本地) 和 id_rsa.pub(公钥文件放在信任服务器)。

在node2上,以用户deven身份进行相同操作。

2. 将所有的公钥文件 id_rsa.pub汇总到一个总的认证文件authorized-keys中:

[deven@node1 ~]$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

[deven@node1 ~]$ ssh deven@node2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

3. 目前node1上存在一份完整的认证key文件,这时候,把它拷到node2主机的对应目录下

[deven@node1 ~]$ scp ~/.ssh/authorized_keys deven@node2:~/.ssh/authorized_keys

用其它的用户也也一样,目标是生成/home/user/.ssh/下的id_rsa, id_rsa.pub,然后将id_rsa.pub追加到集群共享的authorized_keys文件中。

建议将/home/user/.ssh/下所有的文件都设置成700权限。