OpenSSH Change a Passphrase With ssh-keygen command

last updated in Categories , ,

How do I change OpenSSH passphrase for one of my private keys under Linux, OpenBSD, FreeBSD, Apple OS X or Unix like operating systems?

You need to use the ssh-keygen command to generates, change manages and converts authentication keys for ssh. You should the see following files at $HOME/.ssh or ~/.ssh directory i.e. /home/you/.ssh/. You can use the ls -l $HOME/.ssh/ command to see the following files:

=> id_dsa : DSA authentication identity of the user

=> : DSA public key for authentication

=> id_rsa : RSA authentication identity of the user

=> : RSA public key for authentication

Changing a Passphrase with ssh-keygen

The -p option 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. Use -f {filename} option to specifies the filename of the key file. For example, change directory to $HOME/.ssh. Open the Terminal app and then type:
$ cd ~/.ssh/

To change DSA passphrase, enter:
$ ssh-keygen -f id_dsa -p

To change RSA passphrase, enter:
$ ssh-keygen -f id_rsa -p
Sample outputs:

Animated gif 01: Changing your openssh passphrase
Animated gif 01: Changing your openssh passphrase

  • See ssh-keygen(1) man page for information on command line options.


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14 comment

  1. If something relies on the private key will it still work the same way? I mean a SSL certificate for example…

  2. Thank applause and encouragement, for the valid reason that he offers me better power and courage!

  3. This is just what I needed. Thanks! And the animated gif demonstration was extra helpful. :)

  4. Heya,

    Thanks for sharing this useful information. It worked like a charm!

    Just another thing, what tool did you use to capture the screen input to an animated GIF, please?

    Thanks again,

  5. Let’s say I want to give my SSH key used to access some servers to some else (e.g. because I’m not maintaining these servers anymore).

    I can change the password as explained above and give “id_rsa” and “” to this person and he’ll be able to SSH on these servers without changing anything on the servers, right?

    Still, have a question? Get help on our forum!