How to disable autostart of SSHD in Ubuntu 15.04
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.
The command
systemctl disable ssh
did it for me.
@Jakuje: Thanks for giving me the idea.
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
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
I want to disable a service and systemctl disable myservice
doesn't work, but run a systemctl daemon-reload
after disabling makes it disable.