SSH認證免密碼登錄

#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.
[email protected]'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.
[email protected]'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 [email protected]
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 [email protected]:/root/.ssh/authorized_keys
[email protected]'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 ~]#

#如果是普通用戶免密碼登錄也是相同的,用普通用戶登錄,然後在生成密鑰;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章