Failing to change ssh default port on Ubuntu 18.04

October 28, 2019 208 views
Ubuntu 18.04 Security

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?

Thanks

2 Answers

Hello,

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

sudo ufw allow <NewPort>
sudo ufw reload

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
nmap IPADDRESS

Let us know how it goes.

Have another answer? Share your knowledge.