A firewall is a bouncer for your VPS; the trick is telling it about SSH before it starts checking IDs.
Steps
Keep your current SSH session open for the whole process. Know where the Serial console is in the portal (your VPS's page, the Serial console button at the top right), as your way back in if a rule goes wrong. If SSH runs on a port other than 22 (ss -tlnp | grep ssh shows it), use that port number wherever you see 22 below. List the other ports you need open, such as 80 and 443 for a website.
- Log in over SSH as root, or as a user with
sudo. Not sure which firewall your system uses? Debian and Ubuntu use ufw and AlmaLinux uses firewalld.cat /etc/os-releasetells you which system you have, andufw statusorfirewall-cmd --stateshows what's installed. Debian or Ubuntu (ufw):
- Install it if needed:
apt install ufw -y. - Set defaults:
ufw default deny incomingthenufw default allow outgoing. - Allow SSH first:
ufw allow 22/tcp. - Allow what you host: for example
ufw allow 80/tcpandufw allow 443/tcp. - Turn it on:
ufw enable, and answery.
- Install it if needed:
AlmaLinux (firewalld):
- Install and start it if needed:
dnf install firewalld -ythensystemctl enable --now firewalld. - Allow SSH:
firewall-cmd --permanent --add-service=ssh. - Allow web traffic if you need it:
firewall-cmd --permanent --add-service=http --add-service=https. - Apply:
firewall-cmd --reload.
- Install and start it if needed:
- Without closing your existing session, open a second terminal and connect with
ssh -l root YOUR.IP.ADDRESS. If it works, you're safe. - Check the rules:
ufw status verboseorfirewall-cmd --list-all. ufw lists each rule twice, once for IPv4 and once for IPv6. That's normal.
If it didn't work
- If the second login fails, use your still-open session to fix it:
ufw allow 22/tcporfirewall-cmd --permanent --add-service=sshfollowed by--reload. - If you're already locked out, open the Serial console and see our article on recovering from an SSH lockout.
- Still stuck? Open a ticket under Technical Support. Smart VPS is self-managed, so we'll point you in the right direction rather than edit your rules.