如何将密码添加到未经密码生成的OpenSSH私钥?

我使用puttygen生成了OpenSSH私钥(并以OpenSSH格式导出)。 我怎样才能把这个现有的密码(我知道如何生成一个新的密码与密码)密码?

试试命令ssh-keygen -p -f keyfile

从ssh-keygen手册页

  -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. -f filename Specifies the filename of the key file. 

例:

 ssh-keygen -p -f ~/.ssh/id_rsa 

使用-p选项ssh-keygen。 这允许您更改密码而不是生成新的密钥。

以sigjuice显示更改密码:

 ssh-keygen -p -f ~/.ssh/id_rsa 

所需的密码将是新的密码。 (这里假设你已经将public ~/.ssh/id_rsa.pub到了authorized_keys文件中。)用ssh进行testing:

 ssh -i ~/.ssh/id_rsa localhost 

您可以为不同的用途使用不同名称的多个密钥。