Linux: Get Public SSH Key From Private Key

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.

$ ssh-keygen -y -f .ssh/id_ed25519
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICmQudty2vHQlIm8BQx6wMFU4yFE64DOkKD8OUlSsJrt ibrahim@pi4

The .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.

$ ssh-keygen -y -f .ssh/id_ed25519 > .ssh/

The above command will write the public key to .ssh/ file.

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.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }

« Previous Article