Score:0

Unable to Change SSH Port on Ubuntu

ls flag
ami

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!

terdon avatar
cn flag
Please [edit] your question and i) tell us exactly which configuration file(s) you edited and ii) show us the contents of the configuration files. Paste the text into your question, and use the [formatting tools](https://askubuntu.com/help/formatting) to format it as code.
Artur Meinild avatar
vn flag
What is Ubuntu version 24??
muru avatar
us flag
Does this answer your question? [SSH default port not changing (Ubuntu 22.10)](https://askubuntu.com/questions/1439461/ssh-default-port-not-changing-ubuntu-22-10)
terdon avatar
cn flag
By the way, since port 2222 is extremely common, the security benefits of changing to that specific port are debatable.
Artur Meinild avatar
vn flag
@terdon I thought the same thing - port 2222 might be the second most used port for SSH.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.