In older versions of Ubuntu I commented out the "start on ..." line in /etc/init/ssh.conf. This worked well, but not in Ubuntu 15.04.
4 Answers
This is documented in man systemctl
:
systemctl disable ssh
prevents ssh service from automatic starting. But this is the way systemd does it, but ubuntu does not accept it and they have to do it their own way:
Official documentation: https://wiki.ubuntu.com/SystemdForUpstartUsers#Automatic_starting
According to this you should create unit override without directive WantedBy=multi-user.target
in /etc/systemd/system/ssh.service
(instead of the current symlink):
rm /etc/systemd/system/ssh.service
cp /lib/systemd/system/ssh.service /etc/systemd/system/ssh.service
sed -e "/WantedBy=multi-user.target/d" -i /etc/systemd/system/ssh.service
systemctl daemon-reload

- 6,605
- 7
- 30
- 37
I want to disable a service and systemctl disable myservice
doesn't work, but run a systemctl daemon-reload
after disabling makes it disable.

- 111
It does a bit more than requested, but the foolproof approach is to remove the package:
sudo apt-get remove openssh-server
This works in all versions of Ubuntu.
Assuming you have internet access, or have cached the package, reinstalling (and automatically restarting) is not a problem:
sudo apt-get install openssh-server

- 2,836
disable
... I don't know why I put therestatus
. It didn't work for me on Ubuntu (unlike on the other systems) so I was searching also for different solution ... – Jakuje Jul 29 '15 at 05:26ssh
over its aliassshd
. For example,systemctl enable sshd
doesn't work because the aliases cannot be used to enable services. – BeeOnRope Nov 21 '17 at 19:15sshd
and which is more self-explaining. I am not sure why Debian/Ubuntu started using justssh
for the server. I will edit this answer to reflect it. Thanks. – Jakuje Nov 22 '17 at 08:37