Thanks all for this post, took me a while to solve this one, especially as the Debian 10 Buster containers I upgraded past months didn't have this problem. It first occurred when building a Debian 11 Bullseye from scratch.
Because ListenStream can be defined multiple times in a socket service file, the custom value as described in the previous port will be added to the list of ip ports systemd listens on. So in above configuration systemd listens on both 22 and 12345. To replace the ip port the ListenStream parameter must first be cleared and then defined:
Small improvement:Just adding to the thread, as this fixed my issue.
However this is the wrong way to reconfigure systemd services, those changes will be overridden by an apt update.
You should use the systemd override file instead:
systemctl edit ssh.socket
#or
mkdir -p /etc/systemd/system/ssh.socket.d/
cat > /etc/systemd/system/ssh.socket.d/override.conf << EOF
[Socket]
ListenStream=12345
EOF
systemctl daemon-reload
systemctl restart ssh.socket
and the same for the sshd server config
mkdir -p /etc/ssh/sshd_config.d/
cat > /etc/ssh/sshd_config.d/sshd-override.conf << EOF
Port 12345
EOF
Because ListenStream can be defined multiple times in a socket service file, the custom value as described in the previous port will be added to the list of ip ports systemd listens on. So in above configuration systemd listens on both 22 and 12345. To replace the ip port the ListenStream parameter must first be cleared and then defined:
Code:
[Socket]
ListenStream=
ListenStream=12345
Last edited: