SSH密鑰對登錄的原理和實踐


1、ssh密鑰對登錄的基本思路是:要登錄誰,就把公鑰放到誰身上,就可以授權登錄誰。

2、本地登錄設備稱為ssh客戶端,被登錄的設備稱為ssh服務器。

3、原理圖描述如下:

 

4、SSH的公鑰分為openssh格式和IETF格式。

     其中puttygen.exe生成的是IETF格式,ssh-keygen生成的是openssh格式,xshell生成的格式則可選。

 

5、產生秘鑰對的工具軟件。

windows系統:

(1)puttygen.exe

 

(2) xshell工具軟件

 

Linux系統:

ssh-keygen -t rsa 

 

 6、python代碼自動化登錄設備使用paramiko庫進行ssh登錄。對於交換機、路由器等網絡設備,則使用ncclient庫進行連接控制。

參考:http://www.cnblogs.com/gannan/archive/2012/02/06/2339883.html

 

 7、xshell 生成秘鑰的過程。

      

 

8. 通過linux服務器生成ssh 密鑰對的流程如下:

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
b8:bb:65:c6:cc:53:92:18:bf:3f:52:65:34:9f:98:dc root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| |
| o |
| . o * . |
| = . * E |
| o S .o |
| = +. |
| . X. |
| =.o. |
| o. ... |
+-----------------+
[root@localhost ~]#

 

根據上述流程,生成的秘鑰對是id_rsa. 其中以.pub開頭的就是公鑰(id_rsa.pub),另外一個(id_rsa)就是公鑰

 

 9、查看密鑰對中文件內容。

私鑰文件內容:

 

公鑰文件內容: (右側有省略,原文太長)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM