Adding to u1686_grawity answer... Now in Ubuntu 24.04 LTS, it appears sshd-socket-generator checks in the sshd configuration (sshd_config and /etc/ssh/sshd_config.d/ ) for Port and listenaddress directives, then transposes these directives into /run/systemd/generator/ssh.socket.d/addresses.conf as ListenStream directives.
For example if Port 22 was specified in sshd_config, then addresses.conf will receive:
[Socket]
ListenStream=
ListenStream=22
or if sshd_config also contains listenaddress 192.168.1.10, then addresses.conf becomes:
[Socket]
ListenStream=
ListenStream=192.168.1.10:22
- It works also with ipv6.
- Important: the first empty line
ListenStream=erases previousListenStreamdirectives from/etc/systemd/system/ssh.socket, and only keeps the ones fromsshd-socket-generator.
Conclusion:
- run
systemctl edit --full sshdssh.socket, - specify the
BindToDevice=eth0directive, - don't specify any
ListenStream(they won't be taken into account), - then run
sudo systemctl daemon-reload && sudo systemctl restart ssh.socket, - this lets
sshd-socket-generatorcopy thePortsandlistenaddressdirectives from the sshd configuration.
Review your configuration with:
systemctl cat ssh.socketss -tulnsshd -T