#SSH无密码登录要使用公钥与私钥,Linux下可以用ssh-keygen生成公钥/私钥;
#Server1(192.168.4.101)Server2(192.168.4.102)Server1通过ssh免密码登录Server2;
#Server1生成.ssh目录
[root@server1 /]# ssh 192.168.4.102
The authenticity of host '192.168.4.102 (192.168.4.102)' can't be established.
RSA key fingerprint is 01:ac:84:3f:a5:ae:2d:a6:f4:68:f6:3f:e4:6c:33:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.4.102' (RSA) to the list of known hosts.
root@192.168.4.102's password: 		#ctrl+c结束掉
[root@server1 /]#

#Server2生成.ssh目录
[root@server2 /]# ssh 192.168.4.101
The authenticity of host '192.168.4.101 (192.168.4.101)' can't be established.
RSA key fingerprint is 18:4c:a2:18:43:36:57:15:ea:87:6c:20:19:99:e1:b8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.4.101' (RSA) to the list of known hosts.
root@192.168.4.101's password: 		#ctrl+c结束掉
[root@server2 /]#

#Server1生成公钥/私钥
[root@server1 /]# 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:
f4:45:f3:dc:f8:65:28:17:a8:e3:0a:84:24:ca:ea:c9 root@server1.example.com
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
|            o..  |
|  . .      ..+ = |
|.. o .  .  .o * +|
|..  . .. .o. o o.|
|.    .  S...    .|
|.     .   .      |
|o .    . .       |
| E      .        |
|                 |
+-----------------+

#将Server1公钥复制到Server2并改名为authorized_keys
[root@server1 /]# scp /root/.ssh/id_rsa.pub root@192.168.4.102:/root/.ssh/authorized_keys
root@192.168.4.102's password: 
id_rsa.pub                                                              100%  406     0.4KB/s   00:00

#从Server1登录到Server2
[root@server1 /]# ssh 192.168.4.102
Last login: Sat Jul 11 01:19:59 2015 from 192.168.4.100			#直接免密码登录
[root@server2 ~]#

#如果是普通用户免密码登录也是相同的,用普通用户登录,然后在生成密钥;