Ssh – Why not ssh.service but sshd.service

sshsystemd

When you have modified /etc/ssh/sshd_config, you may execute systemctl restart sshd.service to reflect the change. At least in my environment, also, systemctl restart ssh.service works. And systemctl --all list-units ssh* tells me there isn't any service with the name sshd.service. Then why is sshd.service used wide and actually valid?

(I know the name of ssh daemon is sshd but this is not the reasonable reason, I think.)


I executed the following commands on linux mint 19 (ubuntu-base) and volumio 2 (raspbian-base), both of which are based on debian.

systemctl restart sshd.service; echo $? #=> 0
systemctl restart ssh.service; echo $? #=> 0
systemctl --no-legend --all list-units ssh* #=> only ssh.service exists

Best Answer

The ssh service has always been named ssh in /etc/services, probably whatever the distribution, because it's the SSH protocol, not the sshd daemon.

Then it made sense, at least in the Debian implementation and thus Debian derivatives, the same name was chosen to start the service as ... service ssh start which translated into system-V style /etc/init.d/ssh.

This was kept in systemd, again for consistency since the service can be started indifferently with old style or systemd-style way. Still, an alias is also defined for compatibility with other distributions which made a different choice:

[Install]
WantedBy=multi-user.target
Alias=sshd.service

So both can be used on Debian and derivatives and they represent the same service.

Related Question