一、ssh密钥对登陆的基本思路是:要登陆谁,就把公钥放到谁身上,就能够受权登陆谁。html
二、本地登陆设备称为ssh客户端,被登陆的设备称为ssh服务器。python
三、原理图描述以下:linux
四、SSH的公钥分为openssh格式和IETF格式。shell
其中puttygen.exe生成的是IETF格式,ssh-keygen生成的是openssh格式,xshell生成的格式则可选。windows
五、产生秘钥对的工具软件。服务器
windows系统:网络
(1)puttygen.exedom
(2) xshell工具软件ssh
Linux系统:ide
ssh-keygen -t rsa
六、python代码自动化登陆设备使用paramiko库进行ssh登陆。对于交换机、路由器等网络设备,则使用ncclient库进行链接控制。
参考:http://www.cnblogs.com/gannan/archive/2012/02/06/2339883.html
七、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)就是公钥
九、查看密钥对中文件内容。
私钥文件内容:
公钥文件内容: (右侧有省略,原文太长)