I'm currently facing an issue with changing the SSH port on my Ubuntu server. I've tried multiple troubleshooting steps, but I'm still unable to get SSH to listen on the desired port. I'm seeking advice and assistance from the community to help me diagnose and resolve this issue.
Problem:
I initially wanted to change the default SSH port from 22 to 2222 for security reasons.
I've updated the SSH configuration file (/etc/ssh/sshd_config) and set the Port directive to 2222.
After making the change and restarting the SSH service, the service still listens on port 22 instead of the configured port 2222.
Troubleshooting Steps Taken:
- Updated Configuration: I've ensured that the SSH configuration file contains the correct Port directive: Port 2222.
- Restarted SSH: I've restarted the SSH service multiple times using the command:
sudo systemctl restart ssh
.
- Checked Listening Ports: I've used the command
sudo ss -tuln | grep ssh
to check if SSH is listening on the desired port. However, there is no output.
- Verified Syntax: I've confirmed the syntax of the SSH configuration using
sudo sshd -t
, and no errors were reported.
- Firewall Rules: I've added a firewall rule to allow incoming connections on port 2222 using UFW:
sudo ufw allow 2222/tcp
.
- Router Configuration: I've updated my router's port forwarding settings to forward connections on port 2222 to my server's internal IP address.
- System Reboots: I've rebooted the system to ensure that the changes take effect.
Observations and Logs:
- The SSH service status (
sudo systemctl status ssh
) indicates that the service is active and running.
- The service has been stopped and started multiple times in the logs, but it consistently listens on port 22.
- The system logs (
/var/log/auth.log
or /var/log/secure
) do not show any errors related to the SSH service.
- The SSH service received a signal 15 (SIGTERM) in the logs, but I'm unsure why it keeps restarting.
Next Steps:
I'm seeking advice from the community on possible solutions or additional troubleshooting steps to resolve this issue.
Any insights, recommendations, or guidance would be greatly appreciated.
System Information:
- Ubuntu Version: 24
- Router Model: mi 4a
Thank you in advance for your assistance!