In this article, we will explain how to set up SSH without passwords in a Linux operating system. We will be using the command line Terminal application for this purpose. To open the command line Terminal, use the <Ctrl+Alt+T> keyboard shortcut.
We have explained the procedure mentioned in this article on the Ubuntu 20.04 system. More or less the same procedure can be followed in Debian and previous Ubuntu versions.
Follow the steps below to set up SSH without passwords on your Linux system.
Generate A New SSH Key Pair on Local Machine
The first step will be to generate a new SSH key on your local system. To do this, issue the following command in Terminal:
Press Enter to accept all fields as defaults.
The above command will create the keypair, i.e., the public key and the private key. The private key is kept on the system, while the public key is shared. These keys are stored in the .ssh folder.
You can view the keypair generated by entering the following command:
Copy Public Key to Remote Machine
In this next step, copy the public key to the remote system that you want to access from your local system without passwords. We will use the ssh-copy-id command that is by default available in most Linux distributions. This command will copy the public key id_rsa.pub to the .ssh/authorized_keys file in the remote system.
The syntax for ssh-copy-id is as follows:
In our example, the command would be:
On the remote system, you can verify the transfer of the public key by viewing the authorized_keys file.
Set the permission on the authorized_keys file on the remote system to 600. Use the following command to do so:
Set the permission on the .ssh directory on the remote system to 700. Use the following command to do so:
Add Private Key to SSH Authentication Agent on Local Server
In our local machine, we will add the private key to the SSH authentication agent. This will allow us to log into the remote server without having to enter a password every time.
Here is the command to do so:
Login to Remote Server Using SSH Keys
After performing the above steps, try logging into your remote sever. This time, you will be able to log into your remote server without entering a password.
That is all you need to set up SSH login without passwords in a Ubuntu 20.04 system. Remember, you can share the public key with anyone, but never share your private key. Anyone with the private key will be able to log into any system having the matching public key.