Security

How to Secure a VPS: A Practical Checklist for Linux and Windows

By NileVPS Team · Published · 8 min read

اقرأ المقال بالعربي

To secure a VPS, keep the system updated, log in with SSH keys instead of passwords, disable direct root and password logins, allow only the ports you need through a firewall, block repeated login attempts, and keep backups you have actually tested. Protect the control panel with two-factor authentication too, because whoever controls the panel controls the server. On Windows, the same ideas apply to Remote Desktop: strong passwords, restricted access to port 3389 and regular updates.

Any server with a public IP address starts receiving automated login attempts soon after it goes online. That is normal background noise on the internet, not a sign you have been targeted. The steps below make that noise harmless.

Before you start: keep a way back in

Some of these changes can lock you out if you make a typo. Two habits prevent that:

  • Keep your current session open while you test changes in a second terminal window.
  • Know your out-of-band access. In the NileVPS control panel, the browser console (VNC) lets you log in on the server's screen even when SSH or RDP is blocked, and rescue mode lets you repair a system that will not boot.

Taking a snapshot before major changes is also a good idea, so you can roll back.

Linux checklist

The commands below are for Ubuntu and Debian. Notes for Rocky Linux and AlmaLinux are included where they differ. If you have not connected to your server yet, start with how to connect to a VPS via SSH.

1. Update everything

sudo apt update && sudo apt upgrade -y

On Rocky Linux and AlmaLinux, use sudo dnf upgrade -y. Reboot after kernel updates.

Then turn on automatic security updates so you are protected between your own maintenance sessions:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

On Rocky Linux and AlmaLinux, install dnf-automatic, set apply_updates = yes in /etc/dnf/automatic.conf, and enable it with sudo systemctl enable --now dnf-automatic.timer.

2. Use a regular user and SSH keys

Create a non-root user with sudo rights and log in with an SSH key. Our SSH guide covers creating the key, copying it to the server and setting up the user. Do not continue until ssh youruser@your-server-ip works with your key and sudo works for that user.

3. Disable password and root logins

With key login confirmed, tell the SSH server to refuse passwords and direct root logins. Create a small configuration file:

sudo nano /etc/ssh/sshd_config.d/00-hardening.conf

Add these lines and save:

PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no

Why a separate file with 00- in its name? Modern OpenSSH reads files in sshd_config.d in alphabetical order, and for most settings the first value it finds wins. Some cloud images ship a file that turns password login back on, such as 50-cloud-init.conf on Ubuntu. A file starting with 00- is read first, so your settings take effect.

Check the configuration for errors, confirm the effective settings, then reload:

sudo sshd -t
sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin'
sudo systemctl reload ssh

On Rocky Linux and AlmaLinux the service is called sshd, so use sudo systemctl reload sshd. Now open a new terminal and confirm you can still log in with your key before closing the old session.

4. Turn on a firewall

A firewall should allow only the services you actually use. On Ubuntu, ufw is the simplest option; on Debian, install it first with sudo apt install ufw.

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose

Always allow SSH before running ufw enable. Only open ports 80 and 443 if you run a website.

On Rocky Linux and AlmaLinux, firewalld is the default:

sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
If you use Docker, be aware that ports you publish with -p or in Docker Compose can bypass ufw rules, because Docker manages its own firewall rules. Publish database and admin ports only on 127.0.0.1, or rely on a firewall outside the server.

5. Add the cloud firewall as an outer layer

A cloud firewall filters traffic before it reaches your server, so it still protects you if a service inside the server is misconfigured. In the NileVPS control panel you can create firewall rules for your server. A good pattern:

  • Allow TCP 22 (SSH) only from your own IP addresses, if they are stable.
  • Allow TCP 80 and 443 from anywhere for public websites.
  • Do not open database ports such as 3306 or 5432 to the internet.

Using both a cloud firewall and a firewall on the server gives you two independent layers.

6. Block repeated login attempts with fail2ban

fail2ban watches logs for repeated failed logins and temporarily bans the source IP. With password login disabled it is less critical for SSH, but it reduces log noise and helps protect other services.

sudo apt install fail2ban

On Rocky Linux and AlmaLinux, install it from EPEL: sudo dnf install epel-release, then sudo dnf install fail2ban.

Create /etc/fail2ban/jail.local with your own settings rather than editing the default files:

[sshd]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h
backend = systemd

The backend = systemd line tells fail2ban to read the systemd journal, which is needed on systems that do not write SSH logins to /var/log/auth.log, such as Debian 12 and newer. Then start it and check the jail:

sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

7. Reduce what is exposed

  • Remove software you do not use.
  • Check which services listen on the network with sudo ss -tulpn. Anything listening on 0.0.0.0 or [::] is reachable from outside unless a firewall blocks it.
  • Bind databases and caches such as MySQL, PostgreSQL and Redis to 127.0.0.1 unless another server genuinely needs them.
  • Keep web applications and plugins updated; outdated CMS plugins are a common way in.

Backups and snapshots

Security is also about recovering when something goes wrong, whether that is an attack, a bad update or a mistake.

  • Snapshots capture the whole server at a point in time. Take one before upgrades or big configuration changes so you can roll back quickly. NileVPS lets you create snapshots from the control panel.
  • Automated backups run on a schedule without you remembering. On NileVPS they are optional and cost an extra 20% of the plan price.
  • Off-server copies of important data, such as database dumps, uploaded files and configuration, protect you if you lose access to the account or the server itself.

A backup you have never restored is a hope, not a plan. Test a restore at least once, for example by restoring a snapshot to a new server.

Protect the control panel

Your hosting account can reboot, reinstall or open a console on your server, so it needs the same care as the server itself.

  • Turn on two-factor authentication (TOTP) in the NileVPS control panel, using an authenticator app.
  • Use a unique, long password stored in a password manager.
  • Keep the account email secure, because it is used for password resets.

Windows VPS checklist

On a Windows VPS, Remote Desktop on port 3389 is the main door, and automated bots try common passwords against it all day.

  1. Use a strong, unique Administrator password. Long passphrases work well. Never reuse passwords from other services.
  2. Restrict port 3389 in the cloud firewall to your own IP addresses where possible. This single step removes most of the risk.
  3. Keep Network Level Authentication (NLA) enabled. It requires users to authenticate before a full session is created. Run sysdm.cpl, open the Remote tab, and make sure the option to allow connections only from computers using Network Level Authentication is ticked.
  4. Set an account lockout policy. Open secpol.msc and go to Account Policies > Account Lockout Policy to lock accounts for a period after repeated failed logins.
  5. Install Windows updates regularly and reboot when asked. Choose a supported version such as Windows Server 2025 or 2022 for anything exposed to the internet.
  6. Keep Windows Defender Firewall and Microsoft Defender Antivirus on. Only add firewall exceptions for programs that need them.
  7. Create named user accounts for each person instead of sharing the Administrator login, and remove accounts that are no longer needed.
  8. Be careful what you install. Download software only from official sources, especially on trading servers that hold account access.

Changing the RDP port to a non-standard number reduces automated noise, but it is not real protection on its own. Restricting access by IP is far more effective. For connection details, see how to connect to a Windows VPS.

A quick checklist

  • System fully updated, automatic security updates on
  • Regular user with sudo, SSH key login working
  • Password and root SSH login disabled
  • Server firewall allows only needed ports
  • Cloud firewall restricts SSH or RDP to your IPs
  • fail2ban or account lockout enabled
  • Snapshot before changes, automated or off-server backups in place
  • Control panel protected with 2FA

FAQ

What is the most important step to secure a VPS?

For Linux, switching to SSH keys and disabling password login removes the most common attack, password guessing. For Windows, restricting RDP access to your own IP addresses and using a strong password has the biggest effect.

Do I still need fail2ban if password login is disabled?

It is less essential for SSH once passwords are off, but it still cuts log noise and can protect other services such as web logins or mail. It is cheap to run, so many administrators keep it.

Is changing the SSH port worth it?

It reduces automated scanning noise in your logs, but it is not real security. Keys, disabled password login and a firewall do the actual protecting. If you change it, update your firewall rules first.

How often should I update my VPS?

Let automatic security updates handle urgent patches daily, and log in at least monthly to apply all updates, reboot if needed and check that backups are working.

Next step

Security is much easier to build in from the start. Compare plans on pricing, and when you deploy a new server, add your SSH key and set up the cloud firewall before you install anything else.

Related guides