This article is optimized for those looking for immediate changes or the syntax to manage services on Debian, additionally you can find descriptive information on Systemd at the end.
To begin let’s see what services are running to decide what service to discard, to list all services run:
You will see many services with a plus symbol, these are the services running while the services with a minus symbol are not active.
As you can see all listed services are found at /etc/init.d which is where services are stored. You can run ls on /etc/init.d to check:
In my case, a desktop user with a dynamic IP I don’t want the mail service because setting UP SPF, DKIM, etc. may not be impossible but messy, therefore I want to disable the active sendmail service. Some other services like ssh, apache, etc. should be removed if you don’t use them.
The syntax to disable a service on Debian is:
The command to disable sendmail on Debian is
As you can see now the service is disabled
You can also check for the specific service
Currently most Linux distributions don’t use System V anymore but use Systemd.
Systemd is a service manager, it is the PID 1, assigns a control group (cgroup) to each service and can be also useful to track the processes.
Through it you can configure services with the system and service manage which initializes in the last boot process step and manages processes executed by the user.
Below there is a list of commands to manage services through SystemD:
As you can see in the output above SystemD is running.
The following commands lists failed units, services or daemons which didn’t start properly due a misconfiguration, unmatched dependency, etc.
Running the following command is a way to audit the device’s health.
Unit files contain information on sockets, devices, mount points, swap or partition (.service, .socket, .device, .mount, .automount, .swap, .target, .path, .timer, .slice, or .scope). They may contain information on more options. If Systemd fails to identify an option it will log warnings, options starting by X- are ignored.
To list installed unit files run the following command:
List all running services:
To start a service using systemd run:
Alternatively you can run:
To stop services use the same syntax replacing “start” with “ stop”, to start the <Service-name> run:
Similarly, you can use the command “service”:
To restart a service replace “stop” or “start” for “restart”, the following example shows how to start the service “<Service-name>”:
You can also command “service” to restart:
To show the status of a specific service use the option “status”, the following example shows how to start the service <Service-Name>:
You can check a service status using the command “service”:
As you can see the service says to be masked which means it is strongly disabled and can’t be enabled even manually (it can be unmasked but it won’t be shown in this tutorial). The following instructions show how to enable services are meant for disabeld services, not for masked ones.
To enable a service to be activated every time the device boots use the option enable, the following example shows how to enable the <Service-Name> to be started on boot:
To disable a service to remain inactive even after the device boots use the option disable, the following example shows how to enable the <Service-Name> no to be started on boot:
Additionally to disabling services you can also, and it is recommended, to uninstall any service you are sure you won’t use, and even if you plan in the future you can install it, to remove a service, rather than disabling or stopping it, for example to uninstall Apache on Debian run:
You can do the same with all installed services you don’t use such as ssh, cups, etc.
There are additional options for systemctl you can find on its man page or online at http://man7.org/linux/man-pages/man1/systemctl.1.html.
I hope you found this article on Disabling Unnecessary Services Debian Linux useful.