| Sign In | Register
Sinha IT Host

01837072268

support@sinhaithost.com.bd

Cloud VPS & Virtualizor

How to Secure Your Linux VPS with SSH Keys and UFW Firewall

Sinha IT Support November 4, 2026 266 views
How to Secure Your Linux VPS with SSH Keys and UFW Firewall
Summary: Step-by-step instructions to disable password root logins, set up cryptographic SSH keys, and configure UFW firewall rules.

Initial Server Setup: Securing Your New VPS

When you first deploy an Ubuntu or Debian VPS, the default setup allows password logins on port 22. Within minutes, automated botnets will start brute-forcing root credentials. Follow these essential steps to lock down your server.

Step 1: Generate an SSH Key Pair (On Your Local Computer)

ssh-keygen -t ed25519 -C "admin@yourdomain.com"

Copy the public key to your VPS:

ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your-server-ip

Step 2: Disable Password Authentication

Edit the SSH daemon configuration file on your VPS:

sudo nano /etc/ssh/sshd_config

Update these directives:

PasswordAuthentication no
PermitRootLogin prohibit-password

Restart SSH: sudo systemctl restart ssh

Step 3: Configure UFW (Uncomplicated Firewall)

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Now your VPS only accepts connections on authorized ports and enforces key-based authentication!

Was this article helpful?

Your feedback helps us continuously improve our documentation.

Thank you for your feedback!