“By disabling unused services, you can increase your system performance and decrease vulnerability risks. This tutorial explains how to disable services in Debian-based Linux distributions, including Ubuntu.
This article is optimized for both users looking for practical instructions for fast implementation and users looking for a deep understanding of services management. Learning how to disable and manage services is mandatory for all Linux users, independently of their current knowledge level.
The final section (Summary) includes two tables with all explained commands.
All steps described in this document include screenshots, making it easy for every Linux user to reproduce them.”
Disabling Services in Debian and Ubuntu
To begin, let’s see what services are running to decide what service to discard.
To list all services, run the service command followed by the –status-all argument, as shown in the screenshot below.
The list below identifies enabled services with a + and disabled services with a –.
If a service is disabled but not stopped, it will keep running until the next reboot.
To stop the service before disabling it, use the service command followed by the service name and the stop argument. The syntax is shown below.
To show a practical example, I will disable the Bluetooth service, as you can see in the following figure.
To fully disable services use the systemctl command followed by the disable argument and the service name; the syntax is shown below.
To disable the bluetooth service, preventing it from restarting at the next reboot, I would run the following command.
As you can see, the bluetooth service is now inactive because it has a minus (-) symbol next to it instead of a +.
You can check a service status individually by executing the following syntax.
In the practical example shown below, I check the status of the bluetooth service using the syntax shown above.
As you can see, the service is inactive and disabled.
A formidable and recommended way to disable services is by uninstalling them. For example, if you want to remove an apache2 web server on Debian and Ubuntu-based Linux distributions, run the following command, where apache2 is the service you want to remove and disable.
Starting and Enabling Services in Debian and Ubuntu
If you learn how to stop and disable services, you must know how to start and enable them.
You can start services using the systemctl command with the following syntax.
To start the bluetooth service, I would run:
You also can start services using the service command as shown below, where the bluetooth service is started.
Starting a service is not equal to enabling it. If a disabled service is started, it will run until the next reboot.
The first section of this tutorial explained the service command usage to show a service status. You also can check a service status using the systemctl command with the following syntax.
For example, to check the status of the bluetooth service using systemctl, I run the following command.
As you can see, the service is currently running and disabled.
How to Restart and Reload Services in Debian and Ubuntu Linux
When you reconfigure services and need to restart/reload them for changes to take effect, you can use different available options.
For example, to restart the bluetooth service, I run the systemctl command as shown in the image below.
You also can use the service command to restart services using the syntax of the following example, where the bluetooth service is restarted.
Reloading services is a great alternative to restarting. When reloading is available in the service, configuration changes can take effect without a full-service restart, preventing a service interruption.
To reload services using the systemctl command, use the syntax shown in the example below, where the vsftpd service’s configuration is reloaded without interrupting the service (Without restarting).
To reload a service using the service command rather than systemctl, use the following syntax, where vsftpd is reloaded.
Linux Services Management Troubleshooting Commands
Usually, when a service fails, we restart it, or we stop it and then start it back using some of the commands explained previously in this tutorial.
The systemctl command followed by the –failed option will list failed services that were not loaded or started properly, or interrupted.
To show failed services use the following command.
Summary Tables
The systemctl command options to manage services are the following:
ACTION | COMMAND |
Check service status | sudo systemctl status <Service-Name> |
Stop a service | sudo systemctl stop <Service-Name> |
Disable a service | sudo systemctl disable <Service-Name> |
Start a service | sudo systemctl start <Service-Name> |
Enable a service | sudo systemctl enable <Service-Name> |
Reload a service | sudo systemctl reload <Service-Name> |
Restart a service | sudo systemctl restart <Service-Name> |
The service command options to manage services are the following:
ACTION | COMMAND |
Check service status | sudo service <Service-Name> status |
Stop a service | sudo service <Service-Name> stop |
Start a service | sudo service <Service-Name> start |
Reload a service | sudo service <Service-Name> reload |
Restart a service | sudo service <Service-Name> –full-restart |
Conclusion
As you can see, managing services is pretty easy. Any Linux user can disable, enable, start, stop and restart services by running a simple command. As said in the introduction, learning how to manage services is mandatory independently of the user experience; this can be learned at any level. All instructions in this tutorial are valid for all Linux distributions with Systemd system/services manager, which includes most distributions. You don’t need to memorize both systemctl and service command arguments, systemctl offers additional improvements and features, and both man pages are available.
Thank you for reading this tutorial. I hope it was helpful. Keep following us for more professional Linux content.