Prerequisites
Before allowing SSH, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
⚠️ Critical: Always allow SSH BEFORE enabling UFW firewall!
Method 1: Allow Default SSH Port (22)
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
sudo ufw allow ssh
Or explicitly:
sudo ufw allow 22/tcp
Method 2: Allow Custom SSH Port
If you changed SSH port to 2222:
sudo ufw allow 2222/tcp
Method 3: Allow SSH from Specific IP Only (More Secure)
sudo ufw allow from 192.168.1.100 to any port 22
Method 4: Allow SSH Subnet
sudo ufw allow from 192.168.1.0/24 to any port 22
Verify SSH is Allowed
sudo ufw status | grep 22
✅ SSH is now allowed through the firewall.