How to stop all services except ssh?
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.
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, 2022Comments
-
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 over 9 yearspossible duplicate of How to enable or disable services?
-
Panther over 9 yearsI seriously doubt you want to stop all services but ssh.
-
Paulo Coghi over 9 yearsI am doing an operation that is extremely low level and, yes, I need to do exactly this.
-
psusi over 9 yearsThis is not a duplicate of that question.
-
-
Dan Johansen over 9 yearsYou do realize that SSH is of no use to you, without the network service?
-
Hinz over 9 yearsOf 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 over 9 yearsInstead of editing
ssh.conf
, use an Upstart override file. -
psusi over 9 years@muru, good point