开发者

How do I add a password to an OpenSSH private key that was generated without a password?

开发者 https://www.devze.com 2023-01-18 04:41 出处:网络
I generated an OpenSSH private key u开发者_开发百科sing PuTTYgen (and exported it in OpenSSH format).

I generated an OpenSSH private key u开发者_开发百科sing PuTTYgen (and exported it in OpenSSH format).

How can I put a password on this existing key (I know how to generate a new key with a password)?


Try the following command:

ssh-keygen -p -f keyfile

From the ssh-keygen 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.

 -f filename
         Specifies the filename of the key file.

Example:

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


Use the -p option to ssh-keygen. This allows you to change the password rather than generate a new key.

Change the password as sigjuice shows:

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

The required password will be the new password. (This assumes you have added the public key ~/.ssh/id_rsa.pub to your authorized_keys files.) Test with ssh:

ssh -i ~/.ssh/id_rsa localhost

You can have multiple keys with different names for different uses.


You can also use openssl:

openssl rsa -aes256 -in ~/.ssh/your_key -out ~/.ssh/your_key.enc
mv ~/.ssh/your_key.enc ~/.ssh/your_key
chmod 600 ~/.ssh/your_key

see: https://security.stackexchange.com/a/59164/194668


Because you've mentioned "PuTTYgen" and maybe you're using Windows

0

精彩评论

暂无评论...
验证码 换一张
取 消