How to setup SSH keys in Ubuntu 20.04?

Overview

In the SSH protocol, an access credential is known as an SSH key. It serves a similar purpose as usernames and passwords, although system administrators and power users typically use the keys to automate procedures and achieve single sign-on. This is one of the best ways to keep your server secured whilst being able to access it from multiple other VMs.

Let us see how to generate a keypair for Ubuntu 20.04 and then use it to access the host server.

Prerequisites

  • Ubuntu 20.04 installed, or an Ubuntu 20.04 server set up.

  • User account with admin privileges.

  • Second server to access the user account.

  • Working knowledge of the Linux command line.

Get Started

  • This is the host server that we are trying to access.

  • This is the server from which we are trying to access the main server.

Step 1:

  • Enter the following command to generate a key pair.

ssh-keygen

Step 2:

  • You can now enter a file path or press enter to select default path to save your keypair.

  • If you want to overwrite your existing key, press y. This process is not reversable.

  • Your keypair’s fingerprint and random art image is now generated.

Step 3:

  • Enter the command ‘ssh-copy-id username@remote_host’ or ‘ssh-copy-id root@remote_host’ to get the root access.

ssh-copy-id username@remote_host or ssh-copy-id root@remote_host

Step 4:

  • Enter your host server’s password to continue. Once entered you are now connected.

Step 5:

  • Use the command ‘ ssh username@remote_host’ or 'ssh root@remote_host' depending on the acccess you specified to login to the host server.

ssh username@remote_host or ssh root@remote_host
  • You are now logged in to your host server.

Last updated