SSH
Port change
In version from Ubuntu newer than 22.04, the SSHD is controlled by Systemd and no longer with the older process way. To change the port, it needs to be done by changing the config from Systemd
A ssh.socket socket is activated in Systemd to listen to the port, when triggered, it will start the ssh.service (which does not need to be started beforehand, it save memory if no ssh connection is done)
It is done that way on the OVH VPS:
- Changing the port in a
listen.conffile- sudo nano /etc/systemd/system/ssh.socket.d directory (do not change in /lib/systemd...)
[Socket] # Uncomment the following line to turn of listening on port 22. ListenStream= ListenStream=0.0.0.0:xxxxx
The empty ListenStream is necessary to prevent default port
activation. the 0.0.0.0 is for IP v4, use [::] for IP v6. Ubuntu
default instruction for port to be IP v6 is not specified.
Use systemctl show ssh.socket to see the config of the socket
- Restart the services
sudo systemctl daemon-reloadsudo systemctl restart ssh.socket
It seems, it should be possible to only do the change with
sudo systemctl edit ssh.socket
then do the reload/restart
Then, when calling ssh, do not forget to add -p
To check ssh access, use Systemd login:
journalctl -u ssh -n 50 -e --no-pager
In Systemd, 'ssh' without other information is defaulted to service. So ssh.socket needs to be explicit to see the socket instead of the service.
That Systemd logging is used by fail2ban to function.