Development

How to Generate SSH Keys on Ubuntu

Captain Salem 2 min read

How to Generate SSH Keys on 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.

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.

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:

ssh-keygen

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/id_rsa.pub
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.           |
|..ooo . S .      |
|.. o o o . o.    |
|+.  . . = .oo    |
|oo . . = oo+oo   |
|  .   . Eo+o=+.  |
+----[SHA256]-----+

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:

https://www.geekbits.io/how-to-copy-ssh-keys-to-another-machine/

Conclusion

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

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

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

Success! Your billing info has been updated.

Your billing was not updated.