How to Change the SSH Port
Short answerPick a new TCP port, allow it in the firewall first, set Port in sshd_config, reload SSH, and prove a second session works on the new port before you close the old one. Keep noVNC ready in case you lock yourself out.
Overview
Changing the SSH port reduces casual scans on port 22. It is not a substitute for keys and strong auth. Related: SSH Keys vs Password Login · Disable Root SSH Login · console recovery: Console When SSH Fails.
Never change the SSH port and firewall in one untested jump. Keep your current SSH session open until a new session on the new port succeeds.
Before you start
- You can SSH to the VPS on the current port (usually 22)
- You know your primary IP
- Browser console/noVNC opens from the client area
- Choose an unused high port (example:
2222) — avoid ports already used by web/DB services
1) Allow the new port in the firewall
UFW (Ubuntu/Debian):
sudo ufw allow 2222/tcp
sudo ufw statusfirewalld (Alma/Rocky):
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-portsReplace 2222 with your chosen port everywhere in this guide.
2) Set the port in sshd_config
sudo nano /etc/ssh/sshd_configFind the Port line (or add one). Example — listen on both during transition:
Port 22
Port 2222Validate and reload:
sudo sshd -t
sudo systemctl reload sshd 2>/dev/null || sudo systemctl reload ssh3) Test a second SSH session
From your computer (keep the old session open):
ssh -p 2222 root@YOUR_PRIMARY_IP
# or: ssh -p 2222 deploy@YOUR_PRIMARY_IPOnly continue after this login works.
4) Finish the cutover
- In
sshd_config, leave only the new port (removePort 22if you no longer want it) sudo sshd -tthen reload sshd again- Confirm new-port login still works
- Optionally remove the old firewall allow for port 22 after you are sure nothing needs it
5) Update local SSH config (optional)
# ~/.ssh/config
Host vpsgrid
HostName YOUR_PRIMARY_IP
User root
Port 2222
IdentityFile ~/.ssh/id_ed25519Then connect with ssh vpsgrid.
Rollback
- Open noVNC/console
- Restore
Port 22(and firewall allow for 22) - Reload sshd and reconnect normally
Frequently Asked Questions
Do I have to change the SSH port?
No. It is optional obscurity. Prefer SSH keys and careful firewall rules first.
I changed the port and can no longer connect
Use the browser console, fix Port/firewall settings, reload sshd, then retry with ssh -p.
Does VPSGrid block custom SSH ports?
Guest firewall and sshd control reachability on unmanaged plans. If the VPS is online and the guest allows the port, custom SSH ports generally work — still test carefully.
Related Articles
Need More Help?
Open a ticket at billing.vpsgrid.net with your service ID, primary IP, old/new ports, and whether console access works.
Was this answer helpful?