使用 ssh-keygen 更改 ssh 密码会更改 ssh 密钥吗?

Changing ssh passphrase with ssh-keygen makes a change of the ssh key?

我错误地设置了 ssh 密钥的密码。

但是每次使用密钥都要输入密码很烦人。

我想删除我的密钥的密码:

$ ssh-keygen -p -f <my/key/file>

我担心,但是,密钥会被更改。

由于我以多种方式使用密钥,因此该工作似乎太危险而无法测试。

man page 说,命令不会改变我认为的密钥,但不确定:

-p Requests changing the passphrase of a private key file instead of creating a new private key. The program will prompt for the file containing the private key, for the old passphrase, and twice for the new passphrase.

的确,密码只是对私钥文件的本地保护。从 server-perspective 开始,密钥保持不变。

你尝试没有危险。只需在转换前备份您的加密密钥。


虽然正确的解决方案是使用 authentication agent (like OpenSSH ssh-agent)。使用代理,您只需在将密钥加载到代理中时键入一次密码。


如果您 want/need 用于某些自动化的未加密密钥,正确的解决方案是拥有两个密钥。一种加密供交互式使用,另一种未加密供无人值守使用。因此,如果您的未加密密钥被泄露,您可以取消它而无需更换加密密钥。

另一种解决方案是使用 ssh-agent 将您的密码重置为新密码,并将新密码保留为空字符串

  1. 通过终端转到您的 .ssh 文件夹
  2. ssh-keygen -p
  3. 输入您当前的密码
  4. 跟随交互式屏幕,然后连续按两次回车键