In this article, we are going to give you the complete guide on how to login to a VPS server without using a password, aka a passwordless SSH login.
Even though it seems insignificant at first glance, using this method as an alternative way to log in to your VPS Server is actually quite convenient.
Table of Contents
What is Passwordless SSH?
As mentioned before, passwordless SSH is the ability to access a Linux server (VPS) without the need to enter a password. It is an excellent method to get quick access to your server.
While login without password looks like a big security threat, SSH is incredibly secure. It is a SSH key-based authentication method that has a strong encryption and is almost impossible to breach.
Moreover, SSH (Secure Shell) is the most trusted protocol to log into remote servers to run commands and programs. It is also used to transfer files from one computer to another via a network using the Secure Copy Protocol (SCP).
Nonetheless, regardless of the system, choosing a fast and reliable VPS server should always become your first priority.
After all, using a passwordless SSH would still take quite some time if your server is slow to respond and somewhat unreliable.
How to Start Using Passwordless SSH on Linux?
Enabling Passwordless SSH on a Linux Virtual Private Server is not as difficult as you might think. Here are the complete steps to do it:
1. Access Your Server
First of all, you need to use regular SSH to access your VPS. To do this, you can enter a simple command below:
- ssh – the Linux command that must be entered into the terminal, or PuTTY if you’re running a Windows-based machine.
- root – your username
- 18.104.22.168 – your server’s IP address
2. Generate an SSH Key
To generate an SSH key pair that you will use to log in, you need to use this command line:
ssh-keygen -t rsa -b 4096 -C "comment"
Keep in mind that the comment is used as a custom note to help you to identify the key. Since there is a possibility that you will use more than one pair of key, this note would help you to recognize each SSH key you have generated.
Now, you need to determine where to save the key. The default location usually is /home/username/.ssh/id_rsa, but you can choose other places to save them. Suit yourself.
Moreover, there is actually an optional step to enter a password. However, we will not use it since we are tutoring you on how to set up passwordless SSH.
3. Move the Public Key to Another Machine
Moving the public key is easier if you use the same computer that you will use to access the server terminal.
This time, we are going to use the ssh-copy-id command. You need to input this command line:
- root – use your username
- 22.214.171.124 – use your server’s IP address
Now, you have to enter the password of your VPS user. When it is done, copy the SSH key and the connection should be terminated. If you encounter an error, try using this command line:
cat ~/.ssh/id_rsa.pub | ssh email@example.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
- Replace root with your username
- Replace 126.96.36.199 with your server’s IP
Furthermore, for those of you who have already connected to a networked Mac, you can also use Finder. However, make sure that you have made all files visible by showing the hidden files (you can set it up via Desktop Utility).
4. Log in With Passwordless SSH
You are set! Now try to repeat the process from the beginning to access your server. This time, you won’t need to input the password to log in.
How to Disable Passwordless SSH
Disabling passwordless SSH is just as easy as enabling it. If you somehow decided to go back to the old way of typing and scrambling with passwords, follow these steps:
1. Access Your Server Again
First, you need to gain access to the server. Follow the exact methods that we have explained above.
2. Open sshd_config
To open sshd_config you are going to need a text editor such as Vim. Open the text editor then type in this command line:
Now, you need to modify some codes, including:
- PasswordAuthentication no, to PasswordAuthentication yes
- ChallengeResponseAuthentication no, to ChallengeResponseAuthentication yes
- usePAM no, to usePAM yes
After finishing those steps, do not forget to save and exit the file. Most errors in disabling passwordless SSH happen because the users forget to save the codes (it is set to no by default if you are using passwordless SSH!).
3. Restart the SSH Service
You need to restart the SSH service before the effect takes place. Use this root command:
Sudo systemctl restart ssh
Try accessing the server, now that the passwordless SSH has been disabled, you need to input your password manually, like before. If it does not work, try to repeat the process and make sure that you have done all the above steps correctly.
As you can see, setting up passwordless SSH is actually quite easy. We showed you how to do, and how to disable it if it’s not for you.
That is all you need to know about passwordless SSH for a VPS server. Now that you know how to enable and disable this feature, we recommend you to implement this method.
After all, why bother with a complicated, hard-to-remember password if you can log in without one?