How to Enable Passwordless SSH Logins on Linux
As a Linux user, you may find yourself logging in and out of multiple servers throughout the day. Entering your password repeatedly can be tedious, but did you know you can set up passwordless SSH logins? This can save you time and streamline your workflow.
Here’s how to enable passwordless SSH logins on Linux:
Step 1: Generate a Key Pair
The first step is to generate a key pair. The key pair consists of a public key and a private key. The private key will be stored on your local computer, while the public key will be copied to the remote servers you want to access.
To generate a key pair, open a terminal window and type the following command:
$ ssh-keygen -t rsa
You can leave the default settings as they are by pressing Enter, or you can choose to give the key pair a name and password. Once you’ve generated the key pair, you should see two files in the .ssh directory: id_rsa (private key) and id_rsa.pub (public key).
Step 2: Copy the Public Key to the Remote Server
Now, you need to copy the public key to the remote server. To do this, use the ssh-copy-id command. Replace example.com with the IP address or domain name of the remote server:
$ ssh-copy-id [email protected]
The first time you run this command, you will need to enter your password for the remote server. Once you enter your password, the public key will be copied to the remote server’s authorized_keys file, located in the .ssh directory.
Step 3: Test the Passwordless Login
Now, you can test the passwordless login. Open a new terminal window and type the following command:
$ ssh [email protected]
If everything is set up correctly, you should be logged in to the remote server without entering your password.
Step 4: Repeat for Additional Servers
Repeat steps 2 and 3 for any additional servers you want to set up with passwordless SSH logins. You only need to generate a key pair once, but you will need to copy the public key to each server.
Step 5: Disable Password Authentication (Optional)
Now that you have password less SSH logins set up, you may want to disable password authentication altogether. This can improve the security of your servers by eliminating the risk of brute-force attacks on weak passwords.
To disable password authentication, open the sshd_config file on the remote server and look for the line that says Password Authentication. Uncomment it (remove the # symbol) and set it to no:
Password Authentication no
Save the file and restart the sshd service:
$ sudo systemctl restart sshd
Password less SSH logins can save you time and streamline your workflow, but they also come with some security considerations. Make sure to keep your private key secure (use a password to protect it) and always verify the fingerprint of the remote server you’re connecting to. With these precautions in mind, password less SSH logins can be a handy addition to your Linux toolkit.