Secure Shell (SSH) is a communication protocol that allows for secure communication between networked computers. Using this post, you’ll learn how to set up an SSH key-based authentication on Ubuntu Linux and log in without entering a password. If you’re a webmaster or an IT professional managing an SSH server, the most secure way is to set up passwordless authentication and only allow public keys. Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. To get started setting up key-based SSH authentication on Ubuntu, follow the steps below.

How to create SSH keys on Ubuntu Linux

As mentioned above, key-based authentication is the most secure way to log on to an SSH server. If you haven’t already created an SSH key, then run the commands below to create one. The command below generates a new 4096 bits SSH key pair with your email address as a comment. After running the commands above, you’ll be prompted to specify a filename for the keys. In most cases, the default location and filename should work. Next, you’ll be asked to type a secure passphrase. A passphrase adds an extra layer of security so each time you must type the passphrase before you use the key to log in to the remote machine. Press ENTER without typing a passphrase. On your screen, the entire interaction should look similar to the one below. Once done, two new files should be created in your home directory (id_rsa and id_ras.pub). That’s it! You have successfully created a key pair.

How to copy the public key on Ubuntu

Now that you have a keypair, your next step is to copy your public key to the removed SSH server. There are multiple ways to do it. The easiest and recommended way to copy the public key to the server is to use the ssh-copy-id tool. Run the command below to copy your public key to a remote server. Replace the username and server_ip_address with your account on the remote server. You’ll be prompted to type in your SSH password since key-based authentication isn’t yet configured. Once authenticated, the public key ~/.ssh/id_rsa.pub will be appended to the remote user ~/.ssh/authorized_keys file, and the connection will be closed.

How to configure SSH for passwordless login

Now that you’ve copied over your public key, the next step is to disable password authentication. Log on to the remote server with your password, then open the SSH configuration file by running the commands below. In the file, find the lines below and change the value to match these. Save the file and exit. Restart the SSH server on the remote host. After that, password login should be disabled. Next type simply typing the command below will log you in without a password prompt. That should do it! Conclusion: This post showed you how to set up key-based SSH authentication on Ubuntu Linux. If you find any error or want to add something below, please use the comment form.