Change SSH Port (Ubuntu) Print

  • 0

Ubuntu Tools – Change SSH Port

This guide explains how to change the default SSH port in Ubuntu safely.

Steps

  1. Keep your current SSH session open (do not close it yet).
  2. Edit the SSH configuration file:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo nano /etc/ssh/sshd_config

Find:

#Port 22

Change it to (example):

Port 2222
  1. Allow the new port in the firewall before restarting SSH:
sudo ufw allow 2222/tcp
  1. Test the new connection from another terminal:
ssh -p 2222 user@server_ip
  1. If successful, restart SSH and close the old port:
sudo systemctl restart ssh
sudo ufw delete allow 22/tcp

Best Practice: Always test the new port before closing your active session.


Was this answer helpful?

« Back