OpenSSH的RSA/DSA密钥认证系统

OpenSSH的RSA/DSA密钥认证系统,它可以代替OpenSSH缺省使用的标准安全密码认证系统。

OpenSSH的RSA和DSA认证协议的基础是一对专门生成的密钥,分别叫做私用密钥和公用密钥。 使用这些基于密钥的认证系统的优势在于:在许多情况下,有可能不必手工输入密码就能建立起安全的连接。尽管基于密钥的认证协议相当安全,但是当用户并不完全了解这些简化操作对安全性的影响,为了方便而使用某些简化操作时,就会出现问题。

公用密钥用于对消息进行加密,只有拥有私用密钥的人才能对该消息进行解密。公用密钥只能用于加密,而私用密钥只能用于对由匹配的公用密钥编码的消息进行解密。RSA(和 DSA)认证协议利用密钥对的这些特殊性质进行安全认证,并且不需要在网上传输任何保密的信息。ssh 协议的版本 1 使用的是 RSA 密钥,而 DSA 密钥却用于协议级 2,这是 ssh 协议的最新版本

ssh-keygen提示输入密码短语(输入的不是远程服务器上系统账户的密码),输入密码短语后,ssh-keygen用这个密码短语加密了私用密钥,以使私用密钥对于那些不知道这个密码短语的人将变得毫无用处。

创建公钥-私钥对

[root@rhce7 ~]# hostname
rhce7.example.com
[root@rhce7 ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): root1
Enter same passphrase again: root1
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
76:fb:8f:1c:4f:80:81:ec:95:80:aa:87:50:87:fe:0b root@rhce7.example.com
The key's randomart image is:
+--[ DSA 1024]----+
|   .   ..        |
|  o . .. o .     |
| o . .  o +      |
|. . .  . . o     |
| . +    S o .    |
|  E o  . . . .   |
|   o .    . . .  |
|    .      o =   |
|            +.o  |
+-----------------+

将公钥复制到远程系统上的正确位置

[root@rhce7 ~]# ssh-copy-id root@192.168.56.123
The authenticity of host '192.168.56.123 (192.168.56.123)' can't be established.
RSA key fingerprint is da:fe:d3:23:40:eb:d1:01:60:eb:2b:07:8a:2f:e8:73.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.56.123's password: abcd1234

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.56.123'"
and check to make sure that only the key(s) you wanted were added.

通过密钥登录远程服务器

在这过程中,具体包含以下步骤:

1.本地服务器想使用DSA认证协议登录远程服务器
2.远程服务器的sshd会生成一个随机数,并用本地服务器拷贝过来的公钥进行加密后发送给本地服务器
3.本地服务器使用本地私钥对远程服务器发送来的消息进行解密,解密后再把信息发送给远程服务器
4.远程服务器的sshd再次确认信息,信息验证正确后,通过本地服务器的连接登录请求

[root@rhce7 ~]# ssh 192.168.56.123
Enter passphrase for key '/root/.ssh/id_dsa': root1
Last login: Tue Jul 14 09:18:57 2015 from 192.168.56.1
[root@mytest ~]# hostname
mytest.jy.com
原文地址:https://www.cnblogs.com/abclife/p/4643065.html