35

After installing openssh-server, the server start every time I boot. If I want it to be manual what do I need to do?

In version 0.6.7+ of upstart I would add a "manual" stanza to the job file.

10.04 has upstart 0.6.5-8. What is the preferred way to disable ssh from starting automatically in this case?

9 Answers 9

34

Rename /etc/init/ssh.conf to /etc/init/ssh.conf.disabled.

sudo mv /etc/init/ssh.conf /etc/init/ssh.conf.disabled
7
  • 1
    Fast, easy and self-documenting. Perfect.
    – LeartS
    Jan 28, 2014 at 15:47
  • 2
    Possibly even better than echo manual | sudo tee /etc/init/ssh.conf.override , see also how-to-enable-or-disable-services
    – here
    Jan 2, 2015 at 9:48
  • echo manual | sudo tee /etc/init/ssh.conf.override seems like a much better answer, because sudo mv /etc/init/ssh.conf /etc/init/ssh.conf.disabled also prevents starting the server manually without changing it back every time.
    – Brian Z
    Jun 7, 2015 at 4:19
  • @BrianZ ssh.conf.override does not work for me, ssh.override instead.
    – fikr4n
    Feb 28, 2016 at 1:22
  • 1
    This is not the recommended way. You're not telling the OS that the service is not supposed to run. Use update-rc.d (or equivalent) to do that. Jun 27, 2016 at 9:10
23

This should be enough,:

 update-rc.d ssh enable # sets the default runlevels to on 
 update-rc.d ssh disable # sets all to off
3
  • Does this work with an upstart job or just old sys v init scripts?
    – komputes
    Aug 12, 2011 at 16:12
  • This should be enough, even if you're using upstart (dependency-base booting)
    – hhlp
    Aug 13, 2011 at 9:28
  • It says System start/stop links for /etc/init.d/ssh do not exist.
    – fikr4n
    Feb 28, 2016 at 0:57
10

In your /etc/init/ssh.conf, comment out the start on line:

# ssh - OpenBSD Secure Shell server
#
# The OpenSSH server provides secure shell access to the system.

description     "OpenSSH server"

#start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022
1
  • 1
    I'm of the opinion that in general it's better to use the more generic mechanisms that @komputes and hhlp mention. Though this is fine for a single case.
    – belacqua
    Jun 19, 2012 at 17:25
9

For system having systemd the proper way to do it is

sudo systemctl disable ssh.service

then

sudo systemctl stop ssh.service
2
  • 1
    This broke my sshd on 16.04: after that command systemctl enable ssh.service reports "File not found" and I had to purge and reinstall sshd to get it working.
    – BeeOnRope
    Nov 21, 2017 at 18:04
  • You can start the service with sudo systemctl start ssh.service and use systemctl status ssh.service to see if it running or not.
    – Stuart
    Nov 6, 2020 at 14:06
8

note to the reader:

for me (ubuntu 14.xx) only Bryan Agee's answer worked: /etc/init/ssh.conf: comment out the "start on filesystem or runlevel..." line

why won't the others do?

sudo mv /etc/init/ssh.conf /etc/init/ssh.conf.disabled

will result in completly deactivating the service. It is then not startable through "service ssh start" anymore.

update-rc.d ssh enable # sets the default runlevels to on

does simply not work (perhaps uses different autostart routine)

/etc/init/ssh.conf.override with "manual"

simply doesnt work

touch /etc/ssh/sshd_not_to_be_run

also completly disables the system

sudo apt-get install bum

nice software, but it doesn't show ssh, so nothing to do here

person questioning: why are the above answeres even here? is the start system so complicated or does nobody tries his solutions? oO

1
  • And we're only talking about Ubuntu 14.04. Now try to find a universal solution...
    – LatinSuD
    Apr 18, 2017 at 10:58
4
sudo apt-get install bum

Start bum with administrative privileges, disable openssh-server, confirm it, done.

3

For versions with ssh started by upstart, run touch /etc/ssh/sshd_not_to_be_run. The upstart init script checks for this file and, if existent, does not start sshd.

3

The manual method provided /etc/init/ssh.config.override method does not work for me using Ubuntu 14.04.03. sshd still starts automatically.

The /etc/ssh/sshd_not_to_be_run method prevents manual sshd start.

I had to use Brian Agee's method of removing the "start on" on line of /etc/init/ssh.conf. Then to manually start sshd:

sudo service ssh start
2

I had the same question and here's what I did about it. It's a bit of a hack, perhaps, but it works well enough, and you don't need to compromise the program in any way. Put the following in your crontab:

@reboot sudo service ssh stop

This tells cron to stop ssh every time you turn on your computer. Using ssh to connect to another computer isn't affected, as this only turns off the server service. And if you want to re-enable it for a short while, all you have to do is:

sudo service ssh start

Just remember to turn it back off when you're done!

2
  • This works on my Xubuntu 16.04 system which, of course, uses systemd. I don't believe this will work on pre-systemd Ubuntu systems. Nov 28, 2016 at 23:14
  • 1
    Instead of making a cron-job, the proper way would be to disable it with sudo systemctl disable sshd.service, yet as you yourself mentioned your init system is way different to the one in the question. all relevant info about older init systems can be found in the first two answers in this post askubuntu.com/questions/19320/…
    – d1bro
    Nov 28, 2016 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .