Objective: Generate a SSH public key from a private SSH key in OpenSSH format.
SSH keys are generated in pairs – a private key and a public key. If you have lost or misplaced the public key, you can recover it by using the private key.
To recover a public key, use the
-y option of
$ ssh-keygen -y -f .ssh/id_ed25519 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICmQudty2vHQlIm8BQx6wMFU4yFE64DOkKD8OUlSsJrt ibrahim@pi4
.ssh/id_ed25519 is the path to the ssh private key.
ssh-keygen will then print the public key to the screen.
If you would like to write the public key to a file instead, you will just need to redirect the output of
$ ssh-keygen -y -f .ssh/id_ed25519 > .ssh/id_ed25519.pub
The above command will write the public key to
Note that you will not be able to recover/generate a private ssh key from the public key. If you have lost your ssh private key, you will need to generate a new pair of private/public keys.