How to Generate SSH Keys in Ubuntu

In this article, we delve into the process of generating SSH key pairs in Ubuntu and how to copy the resulting keys into a remote machine.
Captain Salem 2 min read
How to Generate SSH Keys in Ubuntu

In the world of secure communication and remote server access, SSH (Secure Shell) keys stand as the cornerstone of authentication. Ubuntu, one of the most widely used Linux distributions, offers a robust platform for implementing SSH key pairs.

Install OpenSSH Tools

Before we can get to the step of generating SSH keys, we need to ensure we have the SSH tools on the target system.

Start by updating the package index with the command:

sudo apt-get update

Next, run the command below to install the SSH tools:

sudo apt-get install openssh-client

This should download and setup all the necessary SSH tools on the host machine.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  openssh-server openssh-sftp-server
Suggested packages:
  keychain libpam-ssh monkeysphere ssh-askpass molly-guard
The following packages will be upgraded:
  openssh-client openssh-server openssh-sftp-server
3 upgraded, 0 newly installed, 0 to remove and 506 not upgraded.

Ubuntu Generate SSH Keys

Once we have the tools installed, we can proceed and generate SSH keys by running the command shown below:


Running the above command should invoke the SSH key generation tools. The above command in interactive and hence will prompt you for various details about your SSH keys. For example, an output is as shown:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/parallels/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/parallels/.ssh/id_rsa
Your public key has been saved in /home/parallels/.ssh/
The key fingerprint is:
SHA256:IlIA+G3RmaijACbStHTwK2oyX+3FVts7pOY/jvWKGM4 parallels@ubuntu-linux-22-04-desktop
The key's randomart image is:
+---[RSA 3072]----+
|o+=..o o         |
|=o.=o +          |
|=..oo.           |
|. +.o.           |
| . S .      |
|.. o o o . o.    |
|+.  . . = .oo    |
|oo . . = oo+oo   |
|  .   . Eo+o=+.  |

For simplicity, you can configure the defaults which will quickly allow you to generate an SSH key pair without hustle.

How to Copy SSH Key To Remote Machine

Luckily, we have an entire tutorial dedicated to the process of copying and uploading an SSH key to your desired machine.

Explore the steps in the tutorial below:

How to Copy SSH Keys to Another Machine
This article shows you how to copy SSH keys to the remote machine to eliminate the redundant process of typing your password every single time you need to log in to a remote machine.


This short tutorial quicly showed you how to generate an SSH key pair on Ubuntu using the ssh-keygen utility.

More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.