Change the SSH Port in Ubuntu Server


Why change the SSH port?

  • Avoid automated scans on port 22
  • Improve overall server security
  • Reduce brute-force attack attempts

Steps to change the SSH port

1. Edit the SSH configuration

  • Connect to your server using the current port:
ssh user@23.175.40.x
  • Edit the configuration file:
sudo nano /etc/ssh/sshd_config
  • Find the line #Port 22 and change it to:
Port 2222
  • Save and exit (CTRL+O, ENTER, then CTRL+X)

2. Allow the new port in the firewall

  • If you're using UFW:
sudo ufw allow 2222/tcp
  • Check active rules:
sudo ufw status

3. Restart the SSH service

sudo systemctl restart ssh

4. Connect using the new port

  • From your SSH client, use:
ssh -p 2222 user@23.175.40.x

Precautions

  • Don't close your current session until you're sure the new port works
  • You can test from a second terminal just in case

Need help?

If you changed the port and lost access, open a ticket at billing.baires.host and we'll help you restore access.

You can also contact us via social media:

Was this answer helpful? 0 Users Found This Useful (0 Votes)