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

No comments:

Post a Comment