Ronalds Vilciņš

Digital Media & Code

Setting up SSH keys on Ubuntu 20.04

Secure Shell (SSH) is a widely used cryptographic network protocol that allows secure remote login and data transfer between computers. One of the key components of SSH is the use of SSH keys, which provide a more secure method of authentication compared to traditional passwords. In this blog post, we will walk you through the process of setting up SSH keys on Ubuntu 20.04, enabling you to enhance the security and efficiency of your remote connections.

Step 1: Checking for existing SSH keys

Before generating new SSH keys, it’s important to check if you already have any pre-existing SSH keys on your Ubuntu 20.04 system. By doing so, you can avoid generating duplicate keys and potential conflicts. Run the following command to check for existing SSH keys:

ls -al ~/.ssh

Step 2: Generating SSH keys

In this step, we’ll guide you through generating a new SSH key pair using the ssh-keygen command. Open a terminal and enter the following command to generate your SSH key pair:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

You will be prompted to enter a file name and choose a passphrase to secure your private key. It is highly recommended to use a strong passphrase to protect your private key.

Step 3: Adding the public key to your remote server

Once you have generated your SSH key pair, the next step is to add the public key to the remote server you want to access. Use the following command to copy your public key to the remote server:

ssh-copy-id username@remote_host

Make sure to replace “username” with your actual username and “remote_host” with the IP address or domain name of your remote server. If ssh-copy-id is not available, you can manually install the key by appending the public key to the ~/.ssh/authorized_keys file on the remote server.

Step 4: Configuring SSH authentication on the client

To utilize the newly generated SSH key for authentication, you need to configure the SSH client on your Ubuntu 20.04 system. Open the SSH configuration file using a text editor:

sudo nano /etc/ssh/sshd_config

Locate the line that says “PasswordAuthentication” and change its value to “no” to disable password-based authentication. Save the file and exit the text editor.

Step 5: Logging in with SSH keys

With the SSH key-based authentication properly set up, you can now log in to the remote server securely and conveniently. Use the following command to initiate an SSH connection:

ssh -i /path/to/private_key username@remote_host

Replace “/path/to/private_key” with the actual path to your private key file, “username” with your username, and “remote_host” with the IP address or domain name of your remote server.