Public and private key pairs are used for publickey authentication method in SSH. When creating the SSH key pair for publickey authentication, you can assign a passphrase to the private key.

A key without a passphrase would allow passwordless login to SSH servers, whereas if a passphrase is assigned, you'll need to key in the passphrase during the publickey login process.

The passphrase of your SSH key can be managed after the key is created. You can add, edit or remove the passphrase on your existing SSH private key using ssh-keygen.

Steps to add passphrase to SSH key

  1. Run ssh-keygen with -p option.
    $ ssh-keygen -p 
  2. Specify the location of your SSH private key.
    Enter file in which the key is (/home/user/.ssh/id_rsa):

    Default location is selected by default

  3. Comment of the private key will be displayed.
    Key has comment 'user@host'
  4. Enter a passphrase for the key twice.
    Enter new passphrase (empty for no passphrase):
    Enter same passphrase again:
  5. Confirmation message will be displayed.
    Your identification has been saved with the new passphrase.

Steps to change passphrase of SSH key

  1. Run ssh-keygen with -p option .
    $ ssh-keygen -p 
  2. Specify the location of your SSH private key.
    Enter file in which the key is (/home/user/.ssh/id_rsa):

    Default location is selected by default

  3. Enter existing passphrase for the private key.
    Enter old passphrase:
  4. Comment of the private key will be displayed.
    Key has comment 'user@host'
  5. Enter a new passphrase for the key twice.
    Enter new passphrase (empty for no passphrase):
    Enter same passphrase again:
  6. Confirmation message will be displayed.
    Your identification has been saved with the new passphrase.

Steps to remove passphrase from SSH key

  1. Run ssh-keygen with -p option .
    $ ssh-keygen -p 
  2. Specify the location of your SSH private key.
    Enter file in which the key is (/home/user/.ssh/id_rsa):

    Default location is selected by default

  3. Enter existing passphrase for the private key.
    Enter old passphrase:
  4. Comment of the private key will be displayed.
    Key has comment 'user@host'
  5. Press [ENTER] twice without entering any passphrase to remove current passphrase.
    Enter new passphrase (empty for no passphrase):
    Enter same passphrase again:
  6. Confirmation message will be displayed.
    Your identification has been saved with the new passphrase.
Discuss the article:

Comment anonymously. Login not required.

Share!