Failing to change ssh default port on Ubuntu 18.04

Hello Everyone,

After installing my droplet (Ubuntu 18.04) I am trying to change the default ssh port (port 22), I tried several ports and on testing the connection times out, HYG what I tried so far:

  1. Changed the port in the file /etc/ssh/sshd_config
  2. Restarted the sshd service using systemctl restart sshd
  3. Also restarted the ssh service using systemctl restart ssh
  4. Tried ssh connecting from outside the droplet using Putty and from another droplet and in both cases the connection times out
  5. Tried ssh connecting from localhost and it works on the new port
  6. Checked the service status using (systemctl status sshd) & (systemctl status ssh) and both are active and listening on the correct port
  7. I also tried adding DO firewall from the console to add a custom port using the new one I added

Don’t know what else to try, can it be related to UFW and how to check/change this?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello, @aymanroshdy2019

You can use telnet or nmap to see if the port is actually open and if you’re able to receive connections on it:

telnet IPADDRESS port

Let us know how it goes.


If the UFW is enabled you need to put the new port in allow list.

sudo ufw allow <NewPort> sudo ufw reload