Adding/Changing the password of an ssh key

If you are a Mac user, and decide to use the OS keychain to unlock your ssh keys, you might want to go back to existing keys you have, and add a password to them. This can be accomplished easily enough with the same ssh-keygen command you use to generate new keys. The command has a -p option to change the password on a key, and that is what you use.

From the ssh-keygen man page:

     -f filename
             Specifies the filename of the key file.

     -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.
 

Remember, you are changing the password on the private key file (i.e. id_rsa, not id_rsa.pub). So, the command would be in the form:

ssh-keygen -p -f .ssh/id_rsa 

This will prompt you for the old passphrase (if it exists), and then for the new password twice. The behavior is very similar to the standard linux passwd command.

Leave a Comment