方法一:

Connection to 192.168.2.100,192.168.2.101

找到/root/.ssh下,删除所有文件,若无.ssh文件夹。相互ssh初始化后,会生成.ssh目录。

[root@localhost ~]# ls /root/.ssh

known_hosts

[root@localhost ~]# cd /root/.ssh

[root@localhost .ssh]# rm -rf *                     #删除所有文件

[root@localhost .ssh]# ssh-keygen

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:

cd:f0:ba:08:0b:31:a6:a7:4f:15:3a:11:24:f4:63:38 root@localhost.localdomain

[root@localhost .ssh]# 

[root@localhost .ssh]# ll

total 8

-rw------- 1 root root 1675 Jun 22 18:43 id_rsa

-rw-r--r-- 1 root root  408 Jun 22 18:43 id_rsa.pub     #生成公钥和私钥

[root@localhost .ssh]# scp id_rsa.pub root@192.168.2.101:/root/.ssh/authorized_keys

The authenticity of host '192.168.2.101 (192.168.2.101)' can't be established.

RSA key fingerprint is 37:1a:c4:32:79:9d:0f:4d:85:94:4e:4b:59:39:19:ea.

Are you sure you want to continue connecting (yes/no)? yes          

Warning: Permanently added '192.168.2.101' (RSA) to the list of known hosts.

root@192.168.2.101's password: 

id_rsa.pub                                   100%  408     0.4KB/s   00:00

                           #上传公钥到客户端.ssh下     

[root@localhost .ssh]# ssh 192.168.2.101

Last login: Sat Jun 21 02:21:49 2014 from 192.168.2.100

Welcome to Dengmin's lab! It's Sat Jun 21 02:23:57 CST 2014       #实现无密码登陆,反之亦然