In this article I will show you how to setup SSH login without passwords in a Linux operating system by using key-based authentication.
SSH is used to remotely log into servers for running the commands and programs. However, sometimes you might want or even need to automatically log in to an SSH server without entering your username and password.
The two most popular mechanisms to log into remote systems via SSH are password-based authentication and key-based authentication.
Username and password combination is the most common authentication method for SSH and is a suitable method for most people. But if you regularly use SSH to connect to remote servers, the key-based authentication method is best for you.
So, can you SSH without a password? In short, yes! Here’s how to do it.
Step 1: Generate SSH Key Pair
The first thing you need to do is generate an SSH key pair on the machine you are currently working on.
If you are not sure exactly how to do it I recommend going through our short and easy to follow guide: Generate an SSH Key Pair [with Examples].
Step 2: Copy Public Key to Remote Server
To enable SSH login without password, you need to transfer a copy of your public key to the remote server. You need to know the credentials and several other details about your remote server – Hostname/IP, Username, Password, Port number.
To transfer the public key to the remote server, we will use the
ssh-copy-id command that is by default available in most Linux distros. The command will copy the content of public key
.ssh/id_rsa.pub to the
.ssh/authorized_keys file in the remote system.
ssh-copy-id [email protected]
You will be prompted to enter the remote username password. Once the user is authenticated, the public key will automatically be copied into the
.ssh/authorized_keys file on the remote server.
On the remote server you can verify the transfer of the public key by viewing the content of the
Step 3: SSH Login Without Password
Now you should be able to login to the remote server without being prompted for a password. Just try to login to your server via SSH:
ssh [email protected]_server
The system should directly log you in to the remote server, no password required.
That is all you need to set up SSH login without passwords. Of course, you can add the same public key to multiple remote serves.
Finally it’s important to note that you can share the public key (
id_rsa.pub) with anyone, but never share your private key (
id_rsa). Only the public key is copied to the server.
The private key should never be copied to another machine, because anyone with the private key will be able to log into any system having the matching public key.
As always, if you have any questions or feedback, feel free to leave a comment.