How to stop all services except ssh?

13,357

Solution 1

What you are looking for is called single user mode. It is a state where only the bare essential services required for the machine to run are running. You enter it either by booting with an 's' argument given to the kernel, or you can switch to it using init s. sshd is not normally considered an essential service though, so it would be stopped. To fix this, you need to edit /etc/init/ssh.conf and add an 'S' to the list of runlevels it should start in and not be stopped in, so it looks like this:

start on runlevel [S12345]
stop on runlevel [!S12345]

Solution 2

I seriously doubt that your system will be still in a useful state after disabling everything but sshd. For a status list of upstart services do:

sudo service --status-all

For System V services:

sudo initctl list

Disable anything that has a + or is listed as start/running with the appropriate commands. To state the blatantly obvious: if you do this via ssh "service network stop" or the like won't do you any good.

Share:
13,357
Paulo Coghi
Author by

Paulo Coghi

Linux infrastructure and cloud manager. Full stack developer. Most importantly, my life is defined by the grace of God given to men through Jesus Christ. It is my ambition that everything I do would reflect His glory and point people towards Him.

Updated on September 18, 2022

Comments

  • Paulo Coghi
    Paulo Coghi over 1 year

    In command line, how can I stop all services from my Ubuntu (Server in this particular case), except SSH?

    And how can I list all services to be sure all of them were stopped?

    • Panther
      Panther over 9 years
      possible duplicate of How to enable or disable services?
    • Panther
      Panther over 9 years
      I seriously doubt you want to stop all services but ssh.
    • Paulo Coghi
      Paulo Coghi over 9 years
      I am doing an operation that is extremely low level and, yes, I need to do exactly this.
    • psusi
      psusi over 9 years
      This is not a duplicate of that question.
  • Dan Johansen
    Dan Johansen over 9 years
    You do realize that SSH is of no use to you, without the network service?
  • Hinz
    Hinz over 9 years
    Of course I assume you know what you're about to do (and wish good luck), but I think the warning had to be given for others reading this.
  • muru
    muru over 9 years
    Instead of editing ssh.conf, use an Upstart override file.
  • psusi
    psusi over 9 years
    @muru, good point