Step-by-Step Guide to Fortify and Secure a Linux VPS Server

Securing your Linux VPS server is an essential step in maintaining the integrity and performance of your server. Whether you’re hosting a website, running applications, or managing sensitive data, following best practices for security is a must. In this comprehensive guide, we’ll walk you through the step-by-step process of securing your Linux VPS server, providing detailed instructions and essential commands to help you fortify your digital fortress.

Step 1: Update and Upgrade

The first and most crucial step is to ensure that your VPS server’s software is up-to-date. Use the following commands to update and upgrade the system:

sudo apt update
sudo apt upgrade

This process will fetch the latest security patches and updates for your server’s operating system.

Step 2: Create a Non-Root User

Running your server as the root user is a security risk. Create a non-root user with sudo privileges and disable root login:

sudo adduser yourusername
sudo usermod -aG sudo yourusername
sudo nano /etc/ssh/sshd_config

Edit the sshd_config file to disable root login:

PermitRootLogin no

Restart the SSH service to apply changes:

sudo service ssh restart

Step 3: Configure a Firewall

Use a firewall to control incoming and outgoing traffic. The Uncomplicated Firewall (UFW) is user-friendly and effective:

sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enable

Make sure you allow only necessary ports and services.

Step 4: SSH Key Authentication

To enhance SSH security, use key-based authentication. Generate a key pair on your local machine:


Copy your public key to the server:

ssh-copy-id yourusername@your_server_ip

Now, you can disable password authentication in the sshd_config:

PasswordAuthentication no

Restart the SSH service again:

sudo service ssh restart

Step 5: Install and Configure Fail2Ban

Fail2Ban is a security tool that monitors login attempts and blocks suspicious IPs. Install and configure it:

sudo apt install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local

Add your desired settings, like banning IPs after a specific number of failed login attempts. Save the file and restart Fail2Ban:

sudo service fail2ban restart

Step 6: Regular Updates and Backups

Set up automatic updates to keep your server secure:

sudo nano /etc/apt/apt.conf.d/10periodic

Modify the file to enable automatic updates:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

Finally, implement a regular backup strategy for your data and configuration files.


Securing your Linux VPS server may require some effort, but the peace of mind and protection it provides are worth every step. By following these instructions and commands, you’ll be well on your way to safeguarding your server against potential threats. Regular maintenance and staying up-to-date with security best practices will help you maintain a strong and secure VPS server, allowing you to focus on your projects without worrying about vulnerabilities.