Programster's Blog

Tutorials focusing on Linux, programming, and open-source

SSH Key Cheatsheet

As with all cheatsheets, this will be added to over time.

For the cheats below, you may replace [key path] with ~/.ssh/id_rsa if you are concerned with just your own computers key rather than a key file.

Create Key

ssh-keygen

Add Passphrase

If you were given an unencrypted SSH key, such as from AWS, then you probably want to add a passphrase to it with the following command:

ssh-keygen -p -f my-private-key.pem

Remove Passphrase

Just do the same again as adding passphrase, this time enter the current passphrase and then don't enter anything for the new one.

ssh-keygen -p -f my-private-key.pem

Generate public key from private key

ssh-keygen -f [key path] -y > [key path].pub

Add Key To Remote Server

Refer here if you wish to see how to easily add this key to a remote server so that you can use it to log in.

Convert RSA PEM Key To OpenSSH Format

The following command will convert the PEM key file in place to the OpenSSH format, so be sure to make a copy if you want to keep the original format too.

ssh-keygen -p -N "" -f /path/to/key

References

Last updated: 25th November 2021
First published: 16th August 2018