Score:0

Unable to change default SSH port

mn flag

using VPS and Ubuntu (latest version). When I changed ssh port by going into sudo nano /etc/ssh/sshd_config it did not work. When checked via sudo lsof -i -n -P | grep LISTEN, it shows it's still listening to port 22. Then when I tried to login again, console showed SSH connection lost.

Then found this thread: SSH default port not changing (Ubuntu 22.10) and I put the commands as:

mkdir -p /etc/systemd/system/ssh.socket.d

cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF

[Socket]

ListenStream=

ListenStream=46876

EOF

sudo systemctl daemon-reload

sudo systemctl restart ssh

When checking systemctl status ssh, it shows failed. Why there is ListenStream two times?

Been at this for too long. Can someone please help me with the commands to change the port?

Thank you.

in flag
Is your server running Ubuntu Server 22.10? Please confirm this, as you're likely using 20.04 or 22.04, which has a different set of steps to follow.
Score:0
mx flag

Seems like you are trying to only restart ssh client and not the server after you make the changes. try this to restart the ssh server and new port configured in sshd config should take effect:

sudo systemctl restart sshd

Also editing systemd directory is for when you want the custom port stay the same even after reboot. Once you reboot, your ssh server resets to 22 until you restart it again after boot up, but modifying that directory will prevent this.

Another key point is that you are using listen.conf that I think should be changed to port.conf, please try below:

mkdir /lib/systemd/system/ssh.socket.d
sudo nano /lib/systemd/system/ssh.socket.d/port.conf

Paste the following and save the file (replace 54747 with custom port):

[Socket]
ListenStream=
ListenStream=54747

Reboot the server after making changes or:

sudo systemctl daemon-reload
sudo systemctl restart ssh
sudo systemctl restart sshd
Score:-1
cw flag

the sshd config file is located at /etc/ssh/sshd_config

just change the port and restart sshd by systemctl restart sshd

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.