it-swarm.cn

如何更改我的私钥密码?

我有一个现有的公钥/私钥对。私钥受密码保护,并且加密可以是RSA或DSA。这些密钥是您使用ssh-keygen生成的密钥,通常存储在~/.ssh下。

我想更改私钥的密码。在标准的Unix shell上,我该如何处理?

另外,如何简单地删除密码?只是将其更改为空?

302
kch

要更改默认DSA密钥上的密码,请执行以下操作:

$ ssh-keygen -p -f ~/.ssh/id_dsa

然后在提示时提供您的旧密码和新密码(两次)。 (如果您有RSA密钥,请使用~/.ssh/id_rsa。)

man ssh-keygen的更多详细信息:

[...]
SYNOPSIS
    ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment]
               [-f output_keyfile]
    ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
[...]
     -f filename
             Specifies the filename of the key file.
[...]
     -N new_passphrase
             Provides the new passphrase.

     -P passphrase
             Provides the (old) passphrase.

     -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.
[...]
392
Mike Mazur