How do I prevent Linux services from auto-starting?

For Ubuntu versions that use systemd (15.04 and later) use:

systemctl disable service

This will do the job. It will disable the service and won't restart after a reboot. To temporarily enable simply start the service. Not enable.

To find the service name use

service --status-all

Other commands are:

systemctl start service - Use it to start a service. Does not persist after reboot

systemctl stop service - Use it to stop a service. Does not persist after reboot

systemctl restart service - Use it to restart a service

systemctl status service - Shows the status of a service. Tells whether a service is currently running.

systemctl enable service - Turns the service on, on the next reboot or on the next start event. It persists after reboot.

systemctl disable service - Turns the service off on the next reboot or on the next stop event. It persists after reboot.


In most linux distributions you can manually start/stop services by (as root or using sudo) running the following commands:

# /etc/init.d/apache2 start
# /etc/init.d/mysqld start

# /etc/init.d/apache2 stop
# /etc/init.d/mysqld stop

Which services that are automatically started is controlled by file links in /etc/rc[runlevel].d/ . Find your current runlevel by using the command "runlevel" as root

# runlevel
N 2

Which here indicates runlevel 2 Now you just have to remove those files in /etc/rc2.d/ which you don't want started.

Removing apache and Mysql on a desktop is usually ok, but be aware of removing other services.


Ubuntu 10.04 is in the middle of a transition between two service management systems: SysVinit (the traditional system, used by most Linux distributions) and Upstart (a newer system pushed by Ubuntu and becoming available in more and more distributions).

SysVinit service management scripts are in /etc/init.d. You can start the service with /etc/init.d/SERVICENAME start and stop it with /etc/init.d/SERVICENAME stop. Whether the service is started automatically on boot depends on the presence of symbolic links in /etc/rc?.d where ? is a digit from 2 to 5 (the runlevel). The easiest way to prevent a service from starting automatically on boot is to use update-rc.d SERVICENAME disable.

Upstart service management configuration files are in /etc/init. You can start the service with start SERVICENAME and stop it with stop SERVICENAME. The configuration file /etc/init/SERVICENAME.conf contains a line indicating when to start the service: start on …. An easy way of disabling these services is to change that line to start on never and (…). If you don't want to edit the file, you can also completely disable the service without confusing the packaging system by renaming it to not end in .conf.

dpkg-divert --add --local --divert /etc/init/foo.conf.disabled --rename /etc/init/foo.conf

As of Ubuntu 10.04, Apache comes with a SysVinit script and Mysql comes with an Upstart script.