SSH: Create Public Key from Private

Usually a public SSH key is generated at the same time as a private key.

Unlike a private SSH key, it is acceptable to lose a public key as it can be generated again from a private key at any time.

In this small note i am showing how to create a public SSH key from a private one using ssh-keygen command-line tool.

Get Public SSH Key from Private

Use the following command to read a private SSH key from a file and print a public key:

$ ssh-keygen -y -f <keyfile>

Short explanation:

Option Description
-y Read a private OpenSSH format file and print an OpenSSH public key to stdout

As an example, let’s generate a public SSH key from a private key ~/.ssh/id_rsa and save it to the file ~/.ssh/id_rsa.pub:

$ ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Start a GUI Application on a Remote Computer using SSH

This article describes how to log into the remote computer (server) using SSH and run a GUI...

SSH Login Slow — Removing Delay

Problem: When I’m trying to log into the remote server via SSH, after I enter the UserName, it...

SSHPass: SSH Login With Password – Command Line

A password-based authentication is often a default way to connect to a remote host over SSH. But...

Signing Failed: Agent Refused Operation [SOLVED]

While attempting to connect to some server over SSH, you may get the error as follows:...

SSH Fingerprint: Get Fingerprint of SSH RSA Key

The fingerprint is a unique sequence of letters and numbers used to identify the SSH RSA key. It...