Base de conocimientos | VPSGrid
BetaEspañol
EnglishBeta EspañolPortuguês (Brasil)Coming soonFrançaisComing soonDeutschComing soonBeta translation — some areas may still appear in English.
Área de cliente

How to Change the SSH Port

KB-044, Linux VPS, VPSGrid, unmanaged 0 found helpful

How to Change the SSH Port

Short answer

Pick 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.

Lockout warning

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 status

firewalld (Alma/Rocky):

sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports

Replace 2222 with your chosen port everywhere in this guide.

2) Set the port in sshd_config

sudo nano /etc/ssh/sshd_config

Find the Port line (or add one). Example — listen on both during transition:

Port 22
Port 2222

Validate and reload:

sudo sshd -t
sudo systemctl reload sshd 2>/dev/null || sudo systemctl reload ssh

3) 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_IP

Only continue after this login works.

4) Finish the cutover

  1. In sshd_config, leave only the new port (remove Port 22 if you no longer want it)
  2. sudo sshd -t then reload sshd again
  3. Confirm new-port login still works
  4. 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_ed25519

Then connect with ssh vpsgrid.

Rollback

  1. Open noVNC/console
  2. Restore Port 22 (and firewall allow for 22)
  3. 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.

¿Le ha resultado útil esta respuesta?

Artículos relacionados