Table of Contents

Secure SSH Access and Best Practices for Ubuntu 22.04 VPS

This guide covers how to disable root SSH access and apply common security best practices for a public-facing Ubuntu 22.04 VPS.

🔐 Disable Root Login via SSH

sudo nano /etc/ssh/sshd_config
PermitRootLogin no

Optional: Use `prohibit-password` to allow only SSH key login for root.

sudo systemctl restart sshd

✅ Essentials

adduser youruser
usermod -aG sudo youruser

On your local machine:

ssh-keygen -t ed25519
ssh-copy-id [email protected]

In /etc/ssh/sshd_config, ensure:

PasswordAuthentication no
  sudo apt update && sudo apt upgrade
  sudo apt install unattended-upgrades
  sudo dpkg-reconfigure --priority=low unattended-upgrades
sudo ufw allow OpenSSH
sudo ufw enable

🛡️ Medium-Hardening

Protects against brute-force SSH attacks.

sudo apt install fail2ban

In /etc/ssh/sshd_config, modify:

Port 2222

Reduces automated scan noise.

sudo ss -tuln

Options include:

📦 Optional Extras

Already covered via `unattended-upgrades`.

Ubuntu uses it by default. Verify with:

sudo aa-status

Use `rsync`, `restic`, or cloud snapshot tools.

Edit with:

sudo visudo

Tools like `libpam-google-authenticator`.

✅ Quick Checklist

  1. 🔲 Root SSH login disabled
  2. 🔲 Password login disabled
  3. 🔲 SSH key authentication configured
  4. 🔲 Non-root user with sudo created
  5. 🔲 UFW firewall enabled
  6. 🔲 Fail2ban installed
  7. 🔲 System updates enabled
  8. 🔲 Backup strategy defined

Last reviewed: 06/06/2025