As far as I know, systemd won't deal with this particularly well. As I understand it, you want to override the behavior of sshd.service
, right?
Luckily for you, systemd is designed for this kind of thing. Simply put your service definition in /etc/systemd/system/ssh.service
, execute systemctl daemon-reload
to reload unit files, and systemd will automatically use that configuration instead of the system ssh.service
.
Want to have systemctl enable mysshd.service
work, too? No problem. In the [Install]
section of your unit file, add a line that says Alias=mysshd.service
. Then execute systemctl reenable ssh.service
to have systemd fix the unit symlinks, and you're golden.
Now, you haven't given details on what mysshd.service
is supposed to do. If it's completely different from the normal ssh.service
, great! Use the method above. However, if you just want to change one small thing, then you're using the wrong approach. systemd allows you to create "snippets" of unit files that will be applied on top of the normal unit files. This lets you add or override individual directives while allowing the rest of the unit file to receive updates from the package manager. To do this, simply create /etc/systemd/system/ssh.d/my-custom-config.conf
(you can change my-custom-config.conf
to be whatever you want, and you can also have multiple override files). In that file, place whatever directives you want to change or add to the usual ssh.service
. You can even add Alias=
directives, so that systemctl start mysshd.service
works! Just remember to execute systemctl daemon-reload
after you're done (and, if you used Alias=
, systemctl reenable ssh.service
).
As an aside, never, ever change systemd unit files in /usr/lib/systemd
. Ever! The Filesystem Hierarchy Standard requires that /usr
is treated as read-only. In practice, this means that the package manager handles /usr
(except for /usr/local
), and you don't touch what the package manager handles - especially because whatever you change will probably eventually be overwritten. Instead, put your stuff in somewhere like /etc
.