使用 AES-256-CBC 生成 SSH 对

使用 AES-256-CBC 生成 SSH 对

好的,创建 ssh 对很容易ssh-keygen,但是如何生成ssh-keygen允许我使用 AES-256-CBC 的 ssh 对?

默认参数始终是 AES-128-CBC,我已经尝试了不同的参数,但它们的功能并不像:

ssh-keygen -b 4096 -t rsa -Z aes-256-cbc

但他们没有工作,知道该怎么做吗?

答案1

你做不是aes生成使用时使用的密钥ssh-keygen。由于aes是一个对称密码,它的键做不是成对出现。通信的两端使用相同的密钥。

ssh-keygen 生成的密钥使用公钥密码学用于身份验证。从ssh-keygen手册:

 ssh-keygen generates, manages and converts authentication keys for
 ssh(1).  ssh-keygen can create RSA keys for use by SSH protocol version 1
 and DSA, ECDSA, Ed25519 or RSA keys for use by SSH protocol version 2.

ssh手册中:

 Public key authentication works as follows: The scheme is based on
 public-key cryptography, using cryptosystems where encryption and
 decryption are done using separate keys, and it is unfeasible to derive
 the decryption key from the encryption key.  The idea is that each user
 creates a public/private key pair for authentication purposes.  The
 server knows the public key, and only the user knows the private key.
 ssh implements public key authentication protocol automatically, using
 one of the DSA, ECDSA, Ed25519 or RSA algorithms.

公钥加密的问题是速度相当慢。对称密钥加密速度更快,并用于ssh实际的数据传输。用于对称加密的密钥是在建立连接后动态生成的(引用手册sshd):

 For protocol 2, forward security is provided through a Diffie-Hellman key
 agreement.  This key agreement results in a shared session key.  The rest
 of the session is encrypted using a symmetric cipher, currently 128-bit
 AES, Blowfish, 3DES, CAST128, Arcfour, 192-bit AES, or 256-bit AES.  The
 client selects the encryption algorithm to use from those offered by the
 server.  Additionally, session integrity is provided through a
 cryptographic message authentication code (hmac-md5, hmac-sha1, umac-64,
 umac-128, hmac-ripemd160, hmac-sha2-256 or hmac-sha2-512).

如果您想使用,aes256-cbc则需要使用 -c 选项在命令行上指定它,其最基本的形式如下所示:

$ ssh -c aes256-cbc user@host

ssh_config您还可以使用逗号分隔的列表在 中指定您首选的密码选择。然而,不建议修改默认值,因为这最好留给专家。 OpenSSH 开发人员在选择默认值时考虑了很多因素并积累了多年的经验。

答案2

如果您想更改用于生成 ssh 连接的私钥/公钥的密码,您可以执行以下操作:

openssl genrsa -aes256 -out private.key 4096
ssh-keygen -y -f private.key > public.key.pub

查看可用于 ssh 连接的密码:

ssh -Q cipher

您的守护进程(sshd - 您正在连接的远程主机)也需要支持您正在连接的密码类型。我认为 sshd 上使用的密码与远程主机中安装的 ssh 相同。因此,ssh -Q cipher在远程主机上执行此操作,您将看到 sshd 支持哪些密码。

PS:如果您尝试使用 openssl 生成公钥,它将不适用于 ssh 连接,不仅因为它的格式不同,而且它的编码方式也不同。有这个帖子显示了如何在两者之间进行转换。

相关内容