Persistent 'Connection Refused' scenarios When Using SSH with Custom Port on Ubuntu 22.04
I'm optimizing some code but I'm wondering if anyone has experience with I tried several approaches but none seem to work. I'm working with a 'Connection refused' behavior when trying to SSH into my Ubuntu 22.04 server after configuring it to use a non-standard port (2222). I've made changes to the SSH configuration file `/etc/ssh/sshd_config` and added the line `Port 2222`. After saving the changes, I restarted the SSH service using `sudo systemctl restart sshd`. However, when I try to connect from my local machine using `ssh -p 2222 user@server_ip`, I get the behavior: `ssh: connect to host server_ip port 2222: Connection refused`. I’ve verified that the SSH service is running using `sudo systemctl status sshd`, and it shows that SSH is active and running. I also checked that the firewall (UFW) is set to allow traffic on port 2222 with `sudo ufw allow 2222/tcp`. Additionally, I confirmed that there are no other services using the same port with `sudo lsof -i :2222`. To troubleshoot further, I checked the logs in `/var/log/auth.log` where I found the following entries: ``` Sep 23 12:34:56 server_name sshd[1234]: Server listening on 0.0.0.0 port 2222. Sep 23 12:34:56 server_name sshd[1234]: behavior: Bind to port 2222 on 0.0.0.0 failed: Address already in use. ``` This indicates that there might be another service trying to bind to port 2222. I ran `sudo netstat -tuln | grep 2222` and found nothing listening on that port. I also restarted the server, hoping that would resolve any binding issues, but I still face the same question. Any suggestions on how to resolve this 'Connection refused' scenario? What other configurations or checks should I perform to diagnose this further? How would you solve this? The project is a service built with Bash. Could this be a known issue? I've been using Bash for about a year now.