RSA 和 DSA 用作公钥加密算法
RSA 和 DSA 密钥用于密码验证,并为两台远程机器之间的数据传输或者连接提供更高的安全性。
- RSA 密钥的最小密钥长度为 768 位,默认长度为 2048 位。DSA 的密钥长度限制为 1024 位,因此可以生成比 DSA 密钥更强的 RSA 密钥。
- 与 RSA 相比,DSA 加密速度更快。
- RSA 可用于加密和签名,而 DSA 只能用于签名。
- RSA 可以与 ssh v1 和 v2 一起使用,而 DSA 只能与 v2 一起使用
使用 RSA 生成 ssh 密钥的步骤如下:
服务器IP:192.168.0.110
客户端 IP:192.168.0.100
此命令将生成一个私有(id_rsa)和一个公共(id_rsa.pub)密钥。
注意:确保在提示时提供空白密码
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y 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: 00:b2:0b:46:b8:63:a0:11:8a:b5:e6:6e:5d:9b:ff:5b root@server.example.com The key's randomart image is: +--[ RSA 2048]----+ |ooo . | |B. + . | |*++ . | |== . . | |..o . S | | . . . o | | o . o E | | . . . | | ..o. | +-----------------+
现在我们需要将公钥复制到我们想要安全shell连接的远程机器上。
现在将公钥从服务器机器复制到客户端(确保客户端机器上存在上述目录和文件,否则我们将不得不手动创建它们)
注意:authorized_keys 是文件而不是目录。
不要误认为它是一个目录并将 id_rsa.pub 复制到其中。
在下面的命令中,我们将文件 id_rsa.pub 复制并重命名为 authorized_keys
# scp /root/.ssh/id_rsa.pub 192.168.0.100:/root/.ssh/authorized_keys
在客户端机器上
# chmod 600 /root/.ssh/authorized_keys # chmod 700 /root/.ssh
现在重新启动服务器和客户端机器上的 ssh 服务
# service sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]
现在尝试连接客户端服务器,我们应该可以在没有密码提示的情况下连接
# SSH 192.168.0.100
更改 RSA 密钥
# ssh-keygen -p
我们可以使用 RSA 身份验证在两个 Linux 机器之间创建无密码连接。
在继续执行此操作的步骤之前,让我们简要了解 RSA。
日期:2020-06-02 22:16:57 来源:oir作者:oir