Back to articles
Security & Anti-DDoS

VPS Security for Beginners: 10 Essential Steps to Protect Your Virtual Server

Protecting your virtual private server (VPS) from cyber threats is crucial when starting with cloud hosting. This guide outlines 10 essential steps to secure your VPS, based on best...

DPTCloud Engineering5 min read
VPS Security for Beginners: 10 Essential Steps to Protect Your Virtual Server

Protecting your virtual private server (VPS) from cyber threats is crucial when starting with cloud hosting. This guide outlines 10 essential steps to secure your VPS, based on best practices at DPTCloud and advanced security techniques. These steps cover system updates, firewall configuration, SSH hardening, user management, and modern threat protection, ensuring a robust security foundation for new users.

1. Regularly Update Your System

Keep your operating system and software packages up to date to patch known security vulnerabilities. Regular updates prevent attackers from exploiting outdated software.

Run the following commands on a Linux system:

sudo apt update && sudo apt upgrade -y

This simple step significantly reduces the risk of attacks targeting known vulnerabilities.

2. Configure a Firewall (UFW)

Use UFW (Uncomplicated Firewall) to allow only necessary ports. This minimizes your server’s attack surface.

Run these commands to allow SSH, HTTP, and HTTPS:

sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Disable all ports not required for your services.

3. Secure SSH with Public Key Authentication

Replace password-based SSH login with public key authentication to prevent brute-force attacks.

Generate an SSH key on your client machine:

ssh-keygen -t ed25519

Copy the public key to your VPS:

ssh-copy-id username@your_vps_ip

Disable password authentication by setting PasswordAuthentication no and PermitRootLogin no in /etc/ssh/sshd_config, then restart SSH:

sudo systemctl restart ssh

4. Create a Non-Root User with sudo Privileges

Avoid logging in as root. Create a standard user with sudo access for administrative tasks.

Create a new user:

sudo adduser username

Add the user to the sudo group:

sudo usermod -aG sudo username

This limits exposure to potential root-level attacks.

5. Replace Fail2Ban with CrowdSec

Fail2Ban is a common tool for blocking brute-force attacks, but CrowdSec offers enhanced protection through community intelligence.

Install CrowdSec:

curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | sudo bash
sudo apt install crowdsec

Initialize the configuration:

sudo crowdsec cli config init

Configure CrowdSec to protect SSH and enable it.

Learn more: Replacing Fail2Ban with CrowdSec: A New Era of VPS Security Through Community Intelligence.

6. Secure Secret Keys with OpenBao

Never store sensitive credentials like API keys or passwords in source code or configuration files. Use OpenBao for secure, multi-environment secret management.

OpenBao enables safe storage and access to secrets across different environments, enhancing overall security.

Learn more: Securing Secret Keys Across Multi-Environment with OpenBao: Comprehensive Secret Management Solution.

7. Deploy Stirling PDF Offline on Docker

If you handle sensitive documents, use Stirling PDF to process files offline without sending them to third-party servers.

Running Stirling PDF on Docker ensures absolute document security for enterprise data.

Learn more: Deploy Stirling PDF Offline on Docker: Absolute Document Security Solution for Enterprises.

8. Enhance Docker Security with gVisor

For Docker applications, use gVisor—a sandbox container developed by Google—to protect your VPS Linux kernel.

gVisor adds a security layer between applications and the kernel, reducing risks from compromised containers.

Learn more: Advanced Docker Security: Deploying gVisor Sandbox Containers Developed by Google to Protect VPS Linux Kernels.

9. Optimize Costs and Security with Nominatim and OpenStreetMap

For mapping services, self-host Nominatim and OpenStreetMap instead of relying on third-party APIs. This saves costs and protects data privacy.

Learn more: Optimizing Costs and Security: Guide to Self-Hosting Maps API with Nominatim and OpenStreetMap.

10. Monitor and Log System Activity

Regularly review system logs to detect suspicious behavior. Use tools like journalctl, tail -f /var/log/auth.log, or monitoring systems like Prometheus and Grafana.

Set up automated alerts for failed login attempts or system configuration changes.

Prerequisites

Verify Security

  • Check firewall status: sudo ufw status
  • Ensure SSH only accepts public keys: sudo grep "PasswordAuthentication" /etc/ssh/sshd_config
  • Verify CrowdSec is running: sudo systemctl status crowdsec
  • Test login using a non-root user

Troubleshooting

  • If SSH login fails, use the VPS console to access and fix the issue.
  • If CrowdSec blocks your IP, remove it from the ban list: sudo crowdsec cli banlist remove
  • If system updates cause issues, use recovery mode or boot from ISO.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478