Security is a huge concern for most website owners. However, you don’t just need to worry about someone breaking into your site’s dashboard – it’s also vital that you protect the Virtual Private Server (VPS) where your website is hosted.
Fortunately, there are steps you can take to secure your VPS against malicious third parties. By modifying your standard security checklist, you can ensure that your virtual server is every bit as safeguarded as your website’s login page.
In this article, we’ll discuss what a VPS is and why it’s different from other hosting solutions. Then we’ll share seven strategies that can keep your virtual setup safe from hackers, malware, and other digital threats. Let’s get started!
1. Choose a Hosting Provider That Prioritizes Security
The most important way to set up a secure VPS is to choose the right hosting provider. Your provider should offer built-in security features, tools, and settings. If you have any questions or concerns regarding security, it also helps to have access to 24/7 customer support.
2. Change Your Default Secure Shell (SSH) Login
Many VPS users connect to their servers using Secure Shell (SSH). This is a network protocol that enables you to communicate with a computer remotely over an unsecured network.
SSH is an important tool for managing your server. However, hackers may try to force their way into your SSH by bombarding it with common passwords in the form of a brute-force attack.
To ensure that you’re accessing SSH safely, we recommend using a strong password. For best results, it should feature a mix of upper and lower case letters, plus numbers and symbols.
We recommend using a minimum of eight characters because longer passwords are more difficult to guess. It’s also wise to avoid common phrases and words, particularly ones that you can be associated with, such as your street name.
3. Monitor Your VPS Server Logs
By monitoring your server logs, you can develop an understanding of what’s normal for your server. This puts you in a strong position to identify any suspicious behavior and stop a potential attack.
4. Set Up a Firewall Using IP Tables
A firewall can prevent unwanted connections to your server, while still allowing legitimate visitors.
As a secure VPS user, you should have access to the iptables program, which is included in most Linux distributions. To start, open your console and verify that you don’t have any rules set by default:
This will return sets of rules or chains for your incoming, outgoing, and forwarding packets. If you want to add a new rule to this chain, you can use the following command:
iptables -A INPUT -p tcp -m tcp --dport 7822 -j ACCEPT
This example enables incoming Transmission Control Protocol (TCP) connections through port 7822, which SSH commonly uses. As an example, let’s add another rule which will enable incoming TCP connections through port 80 (HTTP).
This is the port that servers commonly use to transfer information:
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
If you’ve set up a Secure Sockets Layer (SSL) certificate, you’ll also typically want to enable access through port 443, which is the default for HTTPS. To do so, use the following:
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
You can also use iptables to block an IP address, such as if you’ve identified suspicious behavior originating from a particular source. You can create this rule using the following command:
iptables -I INPUT rulenum -s 'IP address goes here' -j DROP
5. Protect Your VPS Against Malware
It’s smart to monitor your server for malware using a tool such as the cPanel virus scanner. This cPanel program scans your server for all the threats recorded in Clam AntiVirus and the R-FX Networks virus definitions database.
6. Use a Content Delivery Network (CDN)
A brute-force attack is when a malicious third party attempts to break into your server by trying many different password and username combinations. You can make your server much less susceptible to brute-force attacks by following password best practices.
However, some hackers use automated scripts and bots to bombard servers with thousands of login credentials in rapid succession. This means that a long, complex password may not always be enough to ensure a secure VPS.
7. Consider Disabling SSH Logins for the Root Account
The ‘root’ is an administrator-level account. If someone manages to gain access to it, they could perform practically any action on your VPS, including revoking access permissions to other legitimate users.
Since root represents ultimate control over your VPS, you’ll want to protect this highly-privileged account. You may want to consider disabling the root user and allowing another to assume its permissions. At this point, an additional username and password will be required to access root user privileges.
If you decide to disable logins for this account, it’s vital that you first create a normal user account. If you don’t perform this step, you’ll be unable to access your server when you disable the root account. The steps for creating a user account and granting it administrative privileges will vary depending on whether your server is running CentOS or Fedora, Debian, or Ubuntu.
Once you’ve created a normal user account, connect to your secure VPS as root. Then you can open the /etc/ssh/sshd_config file and locate this line:
Change it to the following:
Next, add the below line, being sure to replace “username” with the normal user account you created in the previous step:
You can then save your changes and restart the SSH service using the appropriate command for your Linux distribution. For CentOS and Fedora, this command is:
service sshd restart
If you’re using Debian and Ubuntu, you can enter:
service ssh restart
Next, while you’re still logged in as root, verify that you can log into your new account using SSH. If this fails, check your settings. To avoid getting locked out of your server, it’s important that you don’t exit your root session until you’ve logged into the normal user account.
A VPS can be an affordable alternative to dedicated hosting, but it can also be a target for hackers. If you’re going to keep your virtual server safe, it’s important to take the necessary security precautions.
We recommend paying careful attention to your VPS security logs. Once you learn what’s normal for your particular server, you’ll be in a better position to identify suspicious behavior and take action before it escalates into a security breach. You can also strengthen your server against brute-force attacks by using a CDN and following password best practices.