You can protect a Linux VPS server against external access attempts by setting a strong password for the root user. However, access through brute-force attacks is still possible.
To prevent these attacks as far as possible, one recommended practice is to block access for the root user, log in with a less common username, and then switch to the root user if necessary.
To make these changes, you need to connect to the server over SSH as the root user:
Additional information
You can find more information about accessing your server over SSH in the article: Access Linux over SSH
In this example, we will use the tester user to connect after direct SSH access has been disabled for the root user, but you can specify any username. Follow these steps:
Create the tester user with the adduser command:
# adduser tester
Set a password for the tester user with the command
passwd.
# passwd tester
Note
You can test that the connection works by running the ssh command from the server itself:
# ssh tester@ip.del.servidor
Change the setting from PermitRootLogin yes to PermitRootLogin no in the SSH configuration file. This is usually located at /etc/ssh/sshd_config:
# vi /etc/ssh/sshd_config
Restart the service to apply the changes.
For CentOS:
# /etc/init.d/sshd restart
For Debian/Ubuntu:
# /etc/init.d/ssh restart
Once you have completed the steps above, SSH access as root will no longer be possible. You will need to log in with the user you created and then switch to root using the command su –.