≡ Menu

OpenSSH Change a Passphrase With ssh-keygen command

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

=> id_dsa.pub : DSA public key for authentication

=> id_rsa : RSA authentication identity of the user

=> id_rsa.pub : 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

References
  • See ssh-keygen(1) man page for information on command line options.
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 14 comments… add one }
  • Stu February 4, 2008, 8:07 pm

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

  • JOsh Beauregard October 16, 2009, 2:54 pm

    thanx for the quick mem check

  • Pierre Dej July 19, 2010, 9:20 am

    Thanks for this!

  • bambini vestiti April 2, 2011, 10:42 am

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

  • rebecca September 21, 2012, 12:48 am

    change password key to best family ever

  • Richard November 7, 2013, 5:35 pm

    for newbie like me, I had to also add ‘ssh-add id-rsa’ to make it work. Very helpful tutorial

  • Sumanth November 8, 2013, 10:58 am

    Thank you very much, its indeed a very helpful article

  • Murphy Randle April 23, 2014, 2:51 am

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

  • Giovanni Grimone July 24, 2015, 4:10 pm

    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,
    Giovanni

  • Lucas Pereira Caixeta August 26, 2016, 10:01 am

    Simple, objective and clean explanation.
    Thank you so much!

  • A October 26, 2016, 1:51 pm

    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 “id_rsa.pub” to this person and he’ll be able to SSH on these servers without changing anything on the servers, right?

    • R November 1, 2016, 9:29 am

      Yes, you can do that. Note there is no passphrase on the pub key.

  • kazi shahin November 29, 2016, 1:09 pm

    Forgot my Passphrase, how to set a new Passphrase ?

  • Amit January 10, 2017, 10:30 am

    Thank you, it was very helpful.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , , , , , , , , ,