PortGate

Guides · Linux · 3 min

15-Minute Linux VPS Security Hardening Checklist

A short checklist for a new Linux VPS: updates, SSH keys, a default-deny firewall, and a baseline you can diff later.

Apply this list to a new VPS before you deploy an app. The commands assume Debian or Ubuntu and a sudo user. On another family, use the same controls with that distro's tools.

Update the host first

sudo apt update
sudo apt upgrade -y
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Unattended upgrades should install security updates. Reboot when the kernel changes, and make that reboot part of the checklist rather than a surprise.

SSH

Create an admin user, give it sudo, and copy your public key into ~/.ssh/authorized_keys. Then in /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes

Validate with sudo sshd -t and reload SSH. Keep the current session open and confirm a second login works before you disconnect.

Change the SSH port only if you also update the firewall and your agent config. A new port is not a substitute for keys.

Firewall

Default deny, then allow the few ports you meant to publish.

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

ufw limit rate-limits new SSH connections. If Docker is installed, UFW does not see published container ports. Follow the Docker UFW bypass fix and check docker ps before you trust ufw status.

Accounts and files

  • Remove unused users and empty sudoers drop-ins.
  • Mode 700 on ~/.ssh and 600 on authorized_keys and private keys.
  • Do not run the application as root. A service user that cannot log in over SSH is enough.
  • Keep /etc/passwd, /etc/group, /etc/ssh/sshd_config, and /etc/crontab under a hash baseline. A change should be a planned edit, not a surprise.

Services

Disable what you do not use (sudo systemctl disable --now avahi-daemon is a common example). Bind admin panels and databases to 127.0.0.1. Put TLS in front of anything on 443, and send Strict-Transport-Security once you are sure HTTPS is the only entry. The public SSL scanner can show whether that header, CSP, and a frame policy are present.

After the checklist

Install the PortGate agent in server mode and approve the first heartbeat as the baseline only after the items above are done. Later heartbeats flag a new public port, a firewall that was turned off, a changed hash, or a host that stopped reporting.