SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / server / Questions / 50775
Accepted
kch
kch
Asked: 2009-08-06 21:37:57 +0800 CST2009-08-06 21:37:57 +0800 CST 2009-08-06 21:37:57 +0800 CST

How do I change my private key passphrase?

  • 772

I have an existing public/private key pair. The private key is password protected, and the encryption may be either RSA or DSA. These keys are the kind you generate with ssh-keygen and generally store under ~/.ssh.

I'd like to change the private key's password. How do I go about it, on a standard Unix shell?

Also, how do I simply remove the password? Just change it to empty?

unix ssh ssh-keygen passphrase
  • 3 3 Answers
  • 310239 Views

3 Answers

  • Voted
  1. Best Answer
    Mike Mazur
    2009-08-06T22:01:05+08:002009-08-06T22:01:05+08:00

    To change the passphrase on your default key:

    $ ssh-keygen -p
    

    If you need to specify a key, pass the -f option:

    $ ssh-keygen -p -f ~/.ssh/id_dsa
    

    then provide your old and new passphrase (twice) at the prompts. (Use ~/.ssh/id_rsa if you have an RSA key.)

    More details from man ssh-keygen:

    [...]
    SYNOPSIS
        ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment]
                   [-f output_keyfile]
        ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
    [...]
         -f filename
                 Specifies the filename of the key file.
    [...]
         -N new_passphrase
                 Provides the new passphrase.
    
         -P passphrase
                 Provides the (old) passphrase.
    
         -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.
    [...]
    
    • 531
  2. mivk
    2020-11-20T06:54:13+08:002020-11-20T06:54:13+08:00

    If you don't have ssh-keygen installed, you can also use openssl directly

    key="/path/to/your.key"
    algo="-des3" # or -aes256 or ...
    
    openssl rsa $algo -in "$key" -out "$key.new"
    
    # and replace old key with new one
    mv "$key.new" "$key"
    
    • 2
  3. gauta
    2018-02-21T07:17:56+08:002018-02-21T07:17:56+08:00

    Remove your SSH public/private keys:

    rm ~/.ssh/id_rsa*
    

    Recreate the keypair, choosing a new passphrase:

    ssh-keygen -t rsa -f ~/.ssh/id_rsa
    

    Add the newly created private key to your OS X Keychain to store the passphrase and manage unlocking it automatically:

    ssh-add -K ~/.ssh/id_rsa
    

    Copy the public key to the OS X clipboard for adding to web services like GitHub, etc.

    cat ~/.ssh/id_rsa.pub | pbcopy
    

    Add your newly created public key to the ~/.ssh/authorized_keys file of the remote server. Be sure to ensure the correct permissions of both the remote ~/.ssh folder (700) and ~/.ssh/authorized_keys (600). You may want to investigate using ssh-copy-id to ease this process.

    • -14

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    Ping a Specific Port

    • 18 Answers
  • Marko Smith

    What port does SFTP use?

    • 6 Answers
  • Marko Smith

    Resolve host name from IP address

    • 8 Answers
  • Marko Smith

    How can I sort du -h output by size

    • 30 Answers
  • Marko Smith

    Command line to list users in a Windows Active Directory group?

    • 9 Answers
  • Marko Smith

    What's the command-line utility in Windows to do a reverse DNS look-up?

    • 14 Answers
  • Marko Smith

    How to check if a port is blocked on a Windows machine?

    • 4 Answers
  • Marko Smith

    What port should I open to allow remote desktop?

    • 9 Answers
  • Marko Smith

    What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

    • 3 Answers
  • Marko Smith

    How to determine if a bash variable is empty?

    • 15 Answers
  • Martin Hope
    Davie Ping a Specific Port 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    Deepak Mittal How to run a server on port 80 as a normal user on Linux? 2008-11-11 06:31:11 +0800 CST
  • Martin Hope
    MikeN In Nginx, how can I rewrite all http requests to https while maintaining sub-domain? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner How can I sort du -h output by size 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 What is the difference between double and single square brackets in bash? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch How do I change my private key passphrase? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt How does IPv4 Subnetting Work? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent How to determine if a bash variable is empty? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus How do you find what process is holding a file open in Windows? 2009-05-01 16:47:16 +0800 CST

Related Questions

Trending Tags

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve