Dec 02, 2025
Noviantika G. & Valentinas C.
15min Read
Knowing how to secure your Linux virtual private server is important to avoid cyber threats. However, this is not a one-time task – in addition to applying the best security practices, you must always monitor your virtual private server (VPS).
In this article, we will dive deeper into Linux security and its common vulnerabilities. We will also discuss 16 VPS security tips to prevent cyber attacks on your virtual server.
While Linux VPS security is generally robust, it does have some weaknesses. Many cyber threats can compromise your Linux server’s security and data. Here are the most common ones:
Before implementing any security measures, learn the crucial elements you should monitor in your virtual private server, which include:
This section contains 16 security tips for preventing cyber attacks on VPS hosting.
Your VPS hosting provider must have a strong security infrastructure and offer additional protection to keep your server safe. While users can install extra security features, some are pre-configured.
Depending on the provider, the security features will differ. At Hostinger, we apply comprehensive security practices for all our virtual machine hosting plans to ensure optimal safety, including:
Check out our guide on how to install SSL certificate on Linux running CentOS 7.
Furthermore, Hostinger offers automated backups and live snapshots for easy data restoration in case of cyber attacks or other incidents.
All of this is made easy with managed VPS security, which is recommended to most users. It means the provider handles all your hosting server security features, updates outdated software, and scans for malware. It keeps your VPS server secure with minimal effort.
However, advanced users that want more flexibility and control over their VPS security can still benefit from Hostinger’s self-managed hosting. Users get root access to the VPS servers – plus, we offer a dedicated technical support team for assistance.

If you still use port 22 to access your virtual server via an SSH connection, hacking attempts may be more likely. This is because attackers can scan open ports to perform brute-force attacks and obtain SSH access to the remote server.
We recommend changing your default SSH listening port to protect your data against automated attacks. Here’s how to change the SSH port:
nano /etc/ssh/sshd_config
service ssh restart
systemctl restart sshd.service
Linux VPS has a root user that possesses the most privileges on the operating system and can modify any aspect of the server. Cyber criminals might target this user to gain full access to the server.
Deactivating this account helps improve root access security, safeguarding your server from brute-force attacks. However, we recommend creating an alternative username with the privilege to execute root-level commands for server configuration purposes.
Follow the steps below to disable root login:
nano /etc/ssh/sshd_config
PermitRootLogin=no
service ssh restart
systemctl restart sshd.service
Passwords containing information about your identity or simple passphrases are easy to guess. To prevent successful brute-force attacks, create a long and complicated password with several elements, such as numbers and special characters.
You can use tools like NordPass to easily create and store strong passwords. These IT tools provide various customization options, such as limiting the password length and the used characters.
Don’t use the same password for more than one account, and remember to change it regularly, ideally once every three months. In addition, avoid sharing login credentials for accounts with root privileges to prevent unauthorized server modification.
If you’re only using a password to log in, you may become the target of sniffing attacks. To avoid this, use SSH keys instead of a password for VPS authentication.
These encryption keys are additional login credentials for securing an SSH connection on VPS. Since they’re computer-generated, they can be up to 4096 bits long. That means they are more complex and harder to decipher than a manual root password.
SSH keys come in two sets – public and private. The former is saved on the server, while the latter is stored on the user’s machine. When the server detects a login attempt, it will generate a random string and encrypt it with a public key. The encrypted message only decrypts using the associated private key.
Here’s how to generate an SSH key on a Linux server:
ssh-keygen -t rsa
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
If you are using Hostinger VPS, you can ask Kodee AI assistant to list, add, and remove SSH keys on your server. Simply ask it, “Add this new SSH key to my VPS: your-ssh-key,” and it will handle the task.
Since HTTP traffic has various origins, setting up a firewall for VPS helps filter the requests to ensure only legitimate visitors can access your system. Doing so helps you avoid malicious traffic and potential DDoS attacks.
Linux distributions come with an internal firewall service called iptables. This tool monitors traffic from and to your server using tables. It employs rules called chains to filter incoming and outgoing data packets.
It lets you adjust firewall rules according to your needs. Here’s how to install and check the current iptables configuration on Ubuntu:
sudo apt-get install iptables
sudo iptables -L -v
Terminal will output a list of all iptables rules in detail. Here’s what the output may look like:
The Uncomplicated Firewall (UFW) is a built-in application on Ubuntu that acts as the front end for iptables. Simply put, it will deny all incoming connections and allow outgoing ones, decreasing the risk of potential threats.
You can modify and add rules to the firewall according to your preferences. Here’s how to enable it:
sudo ufw enable
sudo apt-get install ufw
sudo ufw status
Alternatively, use our integrated VPS Firewall on hPanel. Select your VPS and go to Security → Firewall on the left side menu:
Then, create a new firewall configuration. Once created, select the Edit button:
Lastly, create any preferred rules:
Alternatively, Hostinger VPS users can easily configure their server firewall by asking Kodee AI assistant. For example, you can ask it to “List all active firewall rules on my VPS” or “Create a new firewall rule that allows connections to port 12345 from any IP address.”
We also recommend installing Suricata on your Ubuntu system. This tool automatically identifies malicious traffic on your network and its sources, which you can later include in the UFW blocklist.
While commonly used, the file transfer protocol (FTP) connection is unsafe due to the lack of encryption. Even though FTP over transport layer security (TLS) or FTPS encrypts the login credentials, it doesn’t secure the file transmission.
As a result, using either of these connections may put your data at risk. Hackers can easily perform a sniffing attack to steal your login credentials and intercept file transfers.
To avoid this, use the secure file transfer protocol (SFTP) instead. It encrypts all data, including the credentials and transferred files. Furthermore, SFTP protects users from man-in-the-middle attacks, as the client needs to be authenticated before accessing the system.
Follow these steps to set up a secure file transfer protocol connection:
sftp user@server_ipaddress
or
sftp user@remotehost_domainname
sftp -oPort=customport user@server_ipaddress
or
sftp -oPort=customport user@remotehost_domainname
Once you’re connected, an SFTP prompt will appear like the following:
The security software Fail2Ban monitors system logs and blocks hackers after multiple failed logins. In addition, it protects servers against DoS, DDoS, dictionary, and brute-force attacks. Fail2Ban uses iptables and a firewall to ban IP addresses.
Follow these steps to set up the Fail2Ban software package on Ubuntu:
sudo apt-get install fail2ban
Do you want to continue? [Y/n] y
sudo systemctl status fail2ban
If the Fail2Ban software package is active and running, Terminal should return the following:
In addition to setting up a firewall to filter incoming traffic, it’s important to monitor files in your VPS. Virus attacks are one of the main Linux server vulnerabilities, and they can potentially target your servers and damage your data.
That makes installing an antivirus especially crucial. Many options are available, but the most notable one is ClamAV. It’s open-source and used to detect suspicious activity and quarantine unwanted files.
Important! Don’t enable ClamAV if your VPS has less than 2 GB of spare RAM. Doing so may consume all the remaining memory, crashing your server.
Follow these instructions to install ClamAV on CentOS:
sudo yum -y install epel-release
sudo yum clean all
sudo yum -y install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd
A Complete! line will appear, indicating that the installation is finished and ClamAV is running. Here’s how the final output should look:
While an antivirus protects your VPS from threats like trojans and worms, it may be unable to detect newer exploits like zero-day malware.
To enhance your VPS security, pair an antivirus with a malware scanner. This type of software updates the detection rule faster, allowing it to distinguish newer threats on your system.
Linux supports various malware scanners, which you must install manually via Terminal. At Hostinger, all our VPS plans include a free Monarx malware scanner. The tool’s graphical user interface makes it easy to use, especially for non-technical users.

After setting up your VPS, follow these steps to install Monarx:
Important! Restoring a snapshot and rescanning your VPS will reset the current malware diagnostic results. Also, re-install Monarx if you are changing the server’s operating system.
The installation process may take up to 60 minutes. Once installed, access the tool by going to the VPS Dashboard’s sidebar → Security → Malware Scanner. This section displays the automatic scan results, including the number of compromised files.
You can manually clean up the malicious files or use Monarx’s Auto removal tool. This feature automatically deletes the injected malware and quarantines potentially compromised files, enabling you to maintain optimal server security with minimal effort.
To enable auto-removal, purchase the license by pressing Activate on the Auto removal section. It costs $7/month, and the billing cycle will automatically adjust based on your remaining VPS subscription length.
In addition to the malware scanner menu in hPanel, you can directly manage Monarx by asking Kodee AI assistant. For example, you can ask it to set up Monarx on your VPS, uninstall it, summarize scan results, and more.
If you use a public connection, someone may intercept your traffic and steal your data. To avoid this, we recommend setting up a virtual private network (VPN) to combat security threats.
A VPN will provide an alternative IP address for your machine to route traffic through an encrypted tunnel and mask your location. It makes your IP address untraceable, allowing you to maintain anonymity while browsing the internet.
In short, a VPN keeps your data safe and prevents hackers from intercepting your traffic. It works hand in hand with a firewall to provide additional VPS security.
A VPN is also beneficial for users who live in an area with location-based restrictions since it lets them change their IP addresses to bypass internet censorship.
Follow these steps to install OpenVPN on CentOS:
sudo yum install net-tools
curl -O http://swupdate.openvpn.org/as/openvpn-as-2.7.3-CentOS7.x86_64.rpm
sha256sum openvpn-as-*
Alternatively, use Hostinger VPS’s Kodee feature to check the SHA-256 checksum of the package:

sudo rpm --install openvpn-as-*.rpm
passwd openvpn
The new Hostinger KVM VPS plans are compatible with any VPN software available in the market.
If there are many users on your VPS hosting, carefully consider the distribution of control and rights. Providing all users with root privileges will expose your server’s resources and sensitive data to security risks.
To prevent this issue, set a user access limit on your server. You can do so by managing users and granting them different permissions for specific files and system resources.
Linux has a user privileges management feature, which lets you modify system access permissions for different accounts. Simply create a group for users with the same access privileges.
Here’s how to manage users and their privileges on Ubuntu:
sudo addgroup my_group
adduser first_user
sudo usermod -a -G group1,group2 first_user
sudo usermod -aG sudo first_user
sudo chmod -R g+w /directory
We also recommend regularly listing users in your Linux system to check for any malicious entries. It’s important since hackers often create an account in a compromised machine to gain access.
Disabling IPv6 helps avoid security vulnerabilities and makes your VPS hosting less prone to cyber attacks. As hackers often send malicious traffic through IPv6, leaving the protocol open can expose your server to potential security breaches.
Even if you’re not actively using IPv6, some of your programs may open listening sockets on it. When a packet comes in, these programs will process it, even a malicious one.
To keep your operating system and VPS server safe, follow these instructions to disable IPv6 on Ubuntu:
sudo nano /etc/sysctl.d/99-sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
sudo sysctl -p
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
Monitoring your server logs gives insights into what’s happening with your VPS hosting. These logs can also provide detailed information about the VPS condition, including the server load and resource usage, for reporting purposes.
Server log monitoring helps you determine whether the server is experiencing cyber attacks or other security threats. The sooner those vulnerabilities are fixed, the fewer opportunities attackers will have to intercept data.
One of the critical directories on your Linux system is called /var/log. It stores a collection of log files that contain crucial information related to the system, kernel, package managers, and various applications running on the server.
Here’s how to open /var/log on a Ubuntu server for log monitoring:
cd /var/log
ls
sudo cat syslog
Here’s how your VPS logs should look like:
In addition to operating system logs, check the action history in your VPS hosting instance to identify suspicious activities or events. For Hostinger VPS users, you can easily do this by asking Kodee AI assistant, “Check the activity logs in my current VPS.”
Since old software may have vulnerabilities, keeping applications up-to-date helps prevent cyber attacks on your VPS. Developers usually release updates and security patches regularly, so check for the latest versions of your software and install them as soon as possible.
In a Linux operating system, you can run a command to quickly list and install all the available package updates. Here’s how to do it on Debian or Ubuntu:
sudo apt-get update
sudo apt-get upgrade
Meanwhile, follow these steps to do it on CentOS/RHEL:
sudo yum update
sudo yum check-update
We recommend enabling automated updates if you use a content management system (CMS) on your server. In addition, you can create cron jobs, a Linux-based utility that schedules a command or script to run at a specified time and date.
The most convenient way to install and run a cron job on CentOS or RHEL is using the yum-cron service. It will automatically update the software every time a new version is released. Here’s how to set it up on CentOS or RHEL:
sudo yum install yum-cron
sudo systemctl enable yum-cron.service
sudo systemctl start yum-cron.service
sudo systemctl status yum-cron.service
sudo vi /etc/yum/yum-cron.conf
apply_updates = yes
Protecting your VPS server is important since it contains sensitive data. Although Linux is famous for its robust security, the VPS server still has vulnerabilities.
Common cyber attacks and issues in a Linux system include malware, sniffing and brute-force attacks, SQL injections, cross-site scripting (XSS), missing function-level control, and broken authentication.
To avoid them, owners of virtual private servers must know how to monitor the server and operating system to apply robust security measures. To get you started, we have compiled the 16 best VPS hosting security tips:
We hope this article has helped you improve your VPS hosting security. If you have any questions or other tips, please leave them in the comments below.
Check out our guide about web application security and protect your site from cyber attacks.
In this section, we will answer several common questions about VPS security.
VPS security is the resilience of your virtual servers against various cyber threats like SQL injection, malware, and sniffing attacks.
Improving VPS security involves proper server management, bug patching, and applying security features. Your hosting provider’s support, built-in features, and services also determine your VPS security.
Weak VPS security makes your server, websites, and visitors vulnerable to cyber attacks. Such attacks can compromise privacy, leak sensitive data, and cause huge financial losses. For businesses, cyber attacks may tarnish their reputation, driving customers away and slowing down sales.
VPS is commonly more secure than a shared hosting plan due to additional security features, isolated resources, and better website privacy. Meanwhile, VPS and dedicated server hosting offer a similar security level.
However, while dedicated server hosting is generally more secure, it lacks VPS’ automatic failover feature that helps prevent data loss.
Yes, VPS typically has a pre-configured firewall that users can adjust. Several Linux distributions have built-in applications for configuring VPS firewall rules, like Uncomplicated Firewall and iptables.