Monday, December 14, 2020

How to remove or change the passphrase from a private key

If you have a passphrase protected private key you may get bored of typing the passphrase each time or perhaps you wish to change the passphrase. In any case you can use ssh-keygen for both of these operations. You still must know the old passphrase however.

$ ssh-keygen -p -f privatekey_rsa
Enter old passphrase:
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.

Take note that this will overwrite your existing key, so you may wish to create a backup of it before running this operation.

Saturday, December 12, 2020

How to generate public ssh key from private

I often find myself in a situation where I have my private key on the host where I am doing something, but not my public key. While I do have my public key elsewhere sometimes it is just that moment when you wish that you had your public key here so that you could quickly copy it somewhere give it to a friend etc..

Luckily generating a public key from private is possible with the ssh-keygen command.

The command bellow will generate a public key tom_rsa.pub from the tom_rsa private key.

$ ssh-keygen -y -f .ssh/tom_rsa > .ssh/tom_rsa.pub

You can then simply copy your key to the desired server:

$ ssh-copy-id -i .ssh/tom_rsa.pub user@10.20.30.40