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、查看密钥对中文件内容。

私钥文件内容:

 

公钥文件内容: (右侧有省略,原文太长)

 

 

 
 
posted @ 2018-01-28 21:44  Jonson Li  阅读(642)  评论(0编辑  收藏  举报