Managing the passphrase of an SSH private key determines how much damage an exposed key file can cause if it is copied from disk or backups. A strong passphrase ensures that access to the private key file alone is not enough to establish SSH sessions using that identity.
In OpenSSH, public and private keys form a pair used with the publickey authentication method. The public key is placed on servers, while the private key remains on the client and can be encrypted at rest with a passphrase using ssh-keygen. Changing or removing the passphrase re-encrypts the same underlying key material, so authorized keys on servers do not need to be updated.
Because ssh-keygen -p rewrites the private key file in place, keeping a backup copy of the original key reduces the risk of accidental data loss. Removing a passphrase eliminates an important protection boundary, especially on shared or mobile systems, and any running ssh-agent should be reloaded so that cached keys match the new passphrase state.
Related: How to generate SSH key pairs
Related: How to configure passwordless SSH login
Methods to manage passphrase of an SSH key.
$ ssh-keygen -p
The -p option changes the passphrase on an existing private key without generating a new key pair.
Enter file in which the key is (/home/user/.ssh/id_ed25519):
Typical user keys reside under /home/user/.ssh with names such as id_rsa or id_ed25519.
Enter old passphrase:
Key has comment 'user@host'
Enter new passphrase (empty for no passphrase): Enter same passphrase again:
Your identification has been saved with the new passphrase.
$ ssh-keygen -y -f /home/user/.ssh/id_ed25519 Enter passphrase: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHbe3AdFxFsytQyYz0EVjNSpwEoiW1h3UyXj9PybQFLM user@host
A prompt for the new passphrase followed by an SSH public key line confirms that the private key passphrase was applied successfully.
$ ssh-keygen -p
The same command is used for adding, changing, or removing a passphrase; the interaction at the prompts determines the outcome.
Enter file in which the key is (/home/user/.ssh/id_ed25519):
The default path typically points to the primary key for the current account under /home/user/.ssh.
Enter old passphrase:
An incorrect passphrase prevents ssh-keygen from decrypting and rewriting the key, and repeated failures can suggest that the wrong file is being modified.
Key has comment 'user@host'
Enter new passphrase (empty for no passphrase): Enter same passphrase again:
Updating the passphrase does not change the public key, so servers using the existing authorized_keys entries continue to accept this key.
Your identification has been saved with the new passphrase.
$ ssh-keygen -y -f /home/user/.ssh/id_ed25519 Enter passphrase: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHbe3AdFxFsytQyYz0EVjNSpwEoiW1h3UyXj9PybQFLM user@host
Successful decryption with the new passphrase followed by valid public key output shows that the change took effect.
$ ssh-keygen -p
Enter file in which the key is (/home/user/.ssh/id_ed25519):
Enter old passphrase:
Key has comment 'user@host'
Enter new passphrase (empty for no passphrase): Enter same passphrase again:
Removing the passphrase allows anyone with read access to the private key file to authenticate as that key, which significantly reduces security on multi-user or unsecured systems.
Your identification has been saved with the new passphrase.
$ ssh-keygen -y -f /home/user/.ssh/id_ed25519 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHbe3AdFxFsytQyYz0EVjNSpwEoiW1h3UyXj9PybQFLM user@host
Absence of a passphrase prompt before the public key output indicates that the private key is no longer encrypted.