
To secure an unmanaged VPS, update the system, create a non-root user with sudo rights, log in with SSH keys, turn off root and password logins, enable a firewall, add brute-force protection, switch on automatic security updates and keep backups off the server. On an unmanaged VPS nobody else does this for you, so do it before you put any website or data on the server. The steps below work on Ubuntu, Debian, AlmaLinux and Rocky Linux.
Why unmanaged means it is your job
With an unmanaged VPS, the provider keeps the hardware, network and virtualisation running. Everything inside the server is yours: the operating system, software, users, firewall and backups. A new server with an exposed SSH port starts receiving automated login attempts soon after it goes online, so treat the first hour as part of the setup.
Security is ongoing. These steps give you a solid baseline, but you still need to apply updates and check the server regularly.
Step 1: Log in and update everything
Connect with the IP address and root details from your provider: ssh root@your_server_ip. Then install all updates:
- Ubuntu or Debian: apt update then apt upgrade.
- AlmaLinux or Rocky Linux: dnf upgrade.
Reboot if the kernel was updated. If the provider sent you a root password, change it with passwd.
Step 2: Create a user with sudo rights
Day-to-day work should not happen as root. Create a user and give it admin rights:
- Ubuntu or Debian: adduser yourname then usermod -aG sudo yourname.
- AlmaLinux or Rocky Linux: adduser yourname, passwd yourname, then usermod -aG wheel yourname.
Step 3: Use SSH keys instead of passwords
SSH keys are far harder to guess than passwords. On your own computer, create a key pair with ssh-keygen -t ed25519, then copy the public key to the server with ssh-copy-id yourname@your_server_ip. Log in as the new user to confirm the key works before you go further.
Step 4: Harden the SSH configuration
Edit /etc/ssh/sshd_config and set:
- PermitRootLogin no, so nobody can log in directly as root.
- PasswordAuthentication no, so only key-based logins are accepted.
Some systems also have files in /etc/ssh/sshd_config.d/ that override these settings, so check there too. Restart SSH with sudo systemctl restart ssh on Ubuntu and Debian, or sudo systemctl restart sshd on AlmaLinux and Rocky Linux. Keep your current session open and test a new login in a second window. If it fails, you can still fix the setting.
Step 5: Turn on a firewall
Deny incoming traffic by default and allow only what you use: SSH, plus HTTP and HTTPS if the server hosts websites. Use UFW on Ubuntu and Debian or firewalld on Red Hat-based systems. Always allow SSH before enabling the firewall. Our guide How to set up a firewall on your server has the exact commands.
Step 6: Block brute-force attempts
Fail2ban reads your logs and temporarily bans IP addresses that fail to log in repeatedly. Install it with sudo apt install fail2ban or, on AlmaLinux and Rocky Linux, from the EPEL repository with sudo dnf install fail2ban. Enable the sshd jail in /etc/fail2ban/jail.local, start the service with sudo systemctl enable –now fail2ban, and check it with sudo fail2ban-client status sshd.
Step 7: Automate security updates
- Ubuntu or Debian: sudo apt install unattended-upgrades, then sudo dpkg-reconfigure –priority=low unattended-upgrades.
- AlmaLinux or Rocky Linux: sudo dnf install dnf-automatic, set apply_updates = yes in /etc/dnf/automatic.conf, then sudo systemctl enable –now dnf-automatic.timer.
Automatic updates cover security fixes. Still log in regularly to apply larger upgrades and reboot when needed.
Step 8: Remove what you do not use
List listening services with sudo ss -tulpn. Stop and disable anything you do not need. Make sure databases such as MySQL listen only on 127.0.0.1 unless another server genuinely needs to connect.
Step 9: Back up off the server
A backup on the same VPS does not help if the server is lost or compromised. Copy backups to separate storage on a schedule, keep several days of copies, and test a restore. Many providers also offer snapshots, which are useful before risky changes but are not a full backup plan.
Step 10: Watch logs and logins
- Check recent logins with last.
- Read authentication logs with sudo journalctl -u ssh (or sshd), or in /var/log/auth.log on Ubuntu and Debian and /var/log/secure on Red Hat-based systems.
- Watch disk space and unusual CPU use, which can be early signs of a problem.
Frequently asked questions
Should I change the SSH port?
It reduces log noise from automated scans but is not real protection. SSH keys, disabled password login and Fail2ban matter much more. If you change it, update your firewall rule first.
Do I need antivirus on a Linux VPS?
For servers hosting websites, malware scanning is worthwhile, because compromised sites are a common way in. Control-panel servers often use tools such as Imunify360.
What if I do not have time to do all this?
Choose a managed server. The provider handles updates, security software and backups, and you focus on your sites.
How often should I review security?
Check updates and logs weekly, and review users, open ports and backups every few months.
Next step
Tremhost KVM VPS plans are unmanaged, with dedicated cores, NVMe storage and full root access, from $15 a month. If you would rather not secure and maintain the server yourself, Managed cPanel VPS includes cPanel, Imunify360, core updates and daily backups.


