
Why Server Hardening Matters for Your Ubuntu VPS
Key Security Risks Facing Ubuntu VPS in 2026
Running a VPS (Virtual Private Server) with Ubuntu is a popular option for hosting websites and apps. However, even the latest Ubuntu versions face risks like hacking attempts, malware, unauthorized access, and data loss. Attackers scan for servers with weak security and exploit them quickly. In 2026, threats are even more advanced with more automated attacks targeting default settings and weak credentials.
Overview of Security Principles and Hardening Benefits
Server hardening means making your VPS stronger by reducing possible attack points. The main principles are: keeping everything up to date, limiting who can access your VPS, using strong passwords or keys, and controlling which services can run. Hardening secures sensitive data, prevents unauthorized changes, and protects your server from being used in attacks on others.
Prerequisites: What You Need Before You Begin Ubuntu VPS Hardening
Supported Ubuntu Versions (Including Ubuntu 24.04 LTS)
This guide is suitable for most supported Ubuntu VPS versions, including Ubuntu 22.04 LTS and the latest Ubuntu 24.04 LTS. The commands and settings are made for these long-term support versions, known for stability and security.
Tools and Access Requirements
- Ubuntu VPS (with root/sudo access)
- SSH client (like PuTTY or Terminal)
- Basic command-line skills
- At least one non-root user with sudo privileges
Creating a Pre-Hardening Backup
Before making big changes, always back up your server. Use your VPS provider’s snapshot tools or run:
sudo tar -czvf /root/backup.tar.gz /etc /var /home- Download the backup or store it safely in case you need to restore your settings.
Quick Reference: Complete Ubuntu VPS Hardening Checklist (Downloadable PDF)
How to Use This Checklist
The checklist helps you remember each step. Print the PDF version or keep it open while hardening your VPS. Mark off each item as you finish.
Explanation of Verification Marks
- ✅ = Step completed
- 🟡 = Optional/Review
- ❌ = Not done, needs attention
Step 1: System Update and Patch Management for Ubuntu VPS Security
Enabling Automatic Security Updates
Automatic updates help you get the latest security fixes fast. To enable:
- Edit automatic upgrades file:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades - Set:
APT::Periodic::Update-Package-Lists "1";APT::Periodic::Unattended-Upgrade "1";
- Save and exit (Ctrl+O, Enter, Ctrl+X)
Manual Update Commands and Best Practices
Always run manual updates before hardening:
sudo apt updatesudo apt upgrade -y- Reboot if the kernel updates:
sudo reboot
Verifying Update Status
- Check if updates are pending:
sudo apt list --upgradable - Check recent upgrades:
grep " upgrade " /var/log/dpkg.log
Step 2: SSH Hardening Checklist for Ubuntu VPS
Disabling Root Login and Password Authentication
- Edit SSH settings:
sudo nano /etc/ssh/sshd_config - Find and change:
PermitRootLogin noPasswordAuthentication no
- Restart SSH:
sudo systemctl restart sshd
Enforcing SSH Key Authentication
- Generate a key on your local machine:
ssh-keygen -t ed25519 - Upload the key:
ssh-copy-id user@your-vps-ip - Test login:
ssh user@your-vps-ip
Changing Default SSH Port and Setting Up Firewall Rules
- Edit SSH port:
sudo nano /etc/ssh/sshd_configthen changePort 22to a less common number (e.g.,2022). - Add the firewall rule:
sudo ufw allow 2022/tcp - Restart SSH:
sudo systemctl restart sshd
Implementing Multi-Factor Authentication (MFA) for SSH
- Install Google Authenticator:
sudo apt install libpam-google-authenticator - Run on each user:
google-authenticator - Edit
/etc/pam.d/sshdand add:auth required pam_google_authenticator.so - In
sshd_config, setChallengeResponseAuthentication yes - Restart SSH:
sudo systemctl restart sshd
Example SSH Configuration for Ubuntu 24.04
Sample relevant lines for /etc/ssh/sshd_config:
Port 2022 PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication yes PubkeyAuthentication yes
Step 3: Configuring and Hardening the Ubuntu VPS Firewall (UFW)
Setting Up UFW for Default Deny Policy
- Enable UFW:
sudo ufw enable - Set default deny:
sudo ufw default deny incomingsudo ufw default allow outgoing
Allow-Listing Essential Services
- For SSH (replace
2022with your port):sudo ufw allow 2022/tcp - For HTTP:
sudo ufw allow 80/tcp - For HTTPS:
sudo ufw allow 443/tcp
Testing Your Firewall Configuration
- Check status:
sudo ufw status numbered - Test connections from another device to ensure only allowed ports are open.
Step 4: Intrusion Prevention and Monitoring (Fail2Ban & Auditd)
Installing and Configuring Fail2Ban
sudo apt install fail2ban- Copy config file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
- Edit
jail.localto adjust ban times and triggers. - Restart:
sudo systemctl restart fail2ban
Setting Up Auditd for System Activity Monitoring
sudo apt install auditd- Start and enable service:
sudo systemctl enable --now auditd
- To see activities:
sudo ausearch -m USER_AUTH
Reviewing and Fine-Tuning Logs
- Check Fail2Ban bans:
sudo fail2ban-client status sshd - Read Auditd logs:
sudo ausearch - Adjust settings if too many false alarms or missed events.
Step 5: Hardening Users, Accounts, and Permissions
Removing Unnecessary Users and Groups
- List users:
cat /etc/passwd - Remove old or unused accounts:
sudo deluser username
Enforcing Strong Password Policies
- Install password quality checker:
sudo apt install libpam-pwquality
- Edit
/etc/security/pwquality.conffor password rules.
Restricting Use of Sudo and Limiting Privilege Escalation
- List sudo users:
sudo getent group sudo - Remove unnecessary sudo access:
sudo deluser username sudo
Detecting and Fixing Insecure File Permissions
- Find world-writable files:
sudo find / -type f -perm -o+w - Fix permissions as needed:
sudo chmod o-w /path/to/file
Step 6: Securing System Services and Reducing Attack Surface
Identifying and Disabling Unneeded Services and Daemons
- List running services:
sudo systemctl list-units --type=service - Disable unnecessary ones:
sudo systemctl disable --now service_name
Using AppArmor to Confine Critical Applications
- Check AppArmor status:
sudo aa-status - Enable & load profiles:
sudo systemctl enable --now apparmor
- Place critical services (like nginx, mysql) in enforce mode using included profiles.
Kernel Parameter Hardening with sysctl
- Edit settings:
sudo nano /etc/sysctl.conf - Add or update:
net.ipv4.conf.all.rp_filter=1net.ipv4.tcp_syncookies=1kernel.randomize_va_space=2
- Apply changes:
sudo sysctl -p
Step 7: Advanced Hardening Tips and Automation
Scripting the Hardening Process (with Example Scripts)
Automate repeated tasks using scripts. Save commands in a text file, make executable (chmod +x harden.sh), then run ./harden.sh as needed. Always test scripts on a test server first.
Using Security Benchmarks and Compliance Tools
- Check your server using
lynisorcis-catfor a full audit and hardening suggestions: sudo apt install lynissudo lynis audit system
Preparing for Ongoing Maintenance and Security Checks
- Create a habit of checking logs and user lists weekly.
- Enable email alerts for system warnings.
- Keep up-to-date on Ubuntu security advisories.
Verification: How to Validate Your Ubuntu VPS Hardening Steps
Manual Verification Commands
- Check open ports:
sudo ss -tulnp - Review SSH security:
sshd -T | grep -E 'permitrootlogin|passwordauthentication' - Firewall and service status:
sudo ufw status,sudo systemctl status service
Using Automated Tools to Audit Your Hardening
- Scan config with
lynis:sudo lynis audit system - Review audit logs for warnings and suggestions.
Download: Printable Server Hardening Checklist for Ubuntu VPS (2026 Edition)
Get the downloadable PDF version of the Ubuntu VPS Hardening Checklist. Use it offline to track your progress step by step.
FAQ: Server Hardening for Ubuntu VPS – Common Questions Answered
- Q: What if I lock myself out after changing SSH settings?
- A: Use your host’s console access to fix the config or reset the firewall.
- Q: Why block unused ports?
- A: Each open port is a door into your system. Fewer open doors mean fewer ways in for attackers.
- Q: Can I skip steps?
- A: Some steps are optional (e.g., MFA) but skipping key steps weakens your security.
- Q: What is the difference between fail2ban and auditd?
- A: Fail2Ban blocks suspicious logins; Auditd records all key server actions for review.
Summary: Key Takeaways and Next Steps
- Hardening your Ubuntu VPS is critical in 2026 to protect from advanced cyber threats.
- Start with updates, strong SSH settings, and a strict firewall.
- Check users, lock permissions, and use intrusion prevention tools.
- Automate and check your setup often—security is an ongoing process.
- Download the checklist PDF and keep learning for even better protection.
