Ubuntu 18/20/22 SSH Port Change

Change your ssh port:

  • Edit your ssh configuration file:
nano /etc/ssh/sshd_config
  • Find line: #Port 22
  • Uncomment the line
  • Change 22 to your desired port number
  • Save the file
  • Restart SSH service
systemctl restart ssh

Check your firewall UFW

ufw status
Status: active

If your firewall is active, it is possible it would be blocking your newly set port. As such add a firewall rule to allow your new port through the firewall:

ufw allow from any to any port 12345
ufw reload

where 12345 is the ssh port you set, or if you have existing firewall rules, it might be a good idea to add your rule on top of all rules to avoid conflicts:

ufw insert 1 allow from any to any port 12345
ufw reload

That should be all. Try and ssh into your server on your new port.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 401