An SSH private key passphrase protects a copied key file from immediate use. ssh-keygen -p changes a private key’s passphrase locally and requires the existing passphrase when the key is encrypted.

OpenSSH keeps the same key material when changing its passphrase, so servers that trust the matching public key do not need new authorized_keys entries. A forgotten passphrase cannot be displayed or bypassed by ssh-keygen, and it is not the remote account’s login password. Without a saved passphrase or another usable copy of the private key, recovery requires a new key pair and replacement of the trusted public key on each server.

Removing the passphrase lets anyone who can read the private key use it without unlocking it. For fewer prompts while retaining passphrase protection, ssh-agent can hold an unlocked identity for a session.

Steps to add, change, or remove an SSH key passphrase:

  1. Back up the private key file before rewriting it.
    $ cp ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.backup

    The private key here is ~/.ssh/id_ed25519, without the .pub suffix. If your key has another name, use that path throughout. On Windows, ssh-keygen takes the same options, but the key path and the copy and delete commands differ.

    The backup is also a private key, and it keeps the previous protection until you delete it.

  2. Run ssh-keygen -p on the private key, entering the current passphrase if it asks for one.
    $ ssh-keygen -p -f ~/.ssh/id_ed25519
    Enter old passphrase:
    Key has comment 'user@workstation'

    A key with no passphrase skips the Enter old passphrase prompt. A wrong passphrase stops ssh-keygen with incorrect passphrase supplied to decrypt private key and leaves the key unchanged.

    PuTTY .ppk keys need PuTTYgen, and other OpenSSL-readable private keys have a separate procedure.
    Related: How to change a PPK passphrase in PuTTYgen
    Related: How to remove a private key passphrase using OpenSSL

  3. Enter the new passphrase at both prompts, leaving them empty to remove the passphrase.
    Enter new passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved with the new passphrase.

    Typed passphrases are not displayed. The same success line appears when the passphrase is removed.

    A key with no passphrase can be used by anyone who gets a copy of the file.

  4. Check that the key opens with its new passphrase, or with no prompt if you removed it.
    $ ssh-keygen -y -f ~/.ssh/id_ed25519
    Enter passphrase for "/home/user/.ssh/id_ed25519":
    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFfU3SL217w/wv36bEbi4qdC4uWp+0HW/aiIWJPSC2fb user@workstation

    The public key line appears once the new passphrase is accepted. After removing the passphrase, the line prints straight away with no prompt.

  5. Delete the backup after the key opens as expected.
    $ rm ~/.ssh/id_ed25519.backup
Share this guide