Table of Contents#
- A Word of Caution
- Identifying Running Services
- Understanding Service States
- How to Disable a Service
- How to Remove (Uninstall) a Service
- Common Services You Might Consider Disabling
- A Practical Walkthrough: Example with Apache
- Conclusion
- References
A Word of Caution#
Proceed with extreme care. Before disabling or removing any service, ask yourself:
- What is this service for? A quick web search for the service name (e.g., "what is avahi-daemon") will tell you its purpose.
- Do I or any application I use depend on it? Disabling a critical service like
dbusorNetworkManagercan render your system unusable until you re-enable it.
Best Practice: Test disabling a service first before removing it. This allows you to easily revert if something breaks. It's also highly recommended to perform these actions on a test system or when you can afford downtime.
Identifying Running Services#
The first step is to see what's running on your system. The method depends on your Linux distribution, but most modern distributions use systemd.
Using systemctl (Systemd Systems)#
Systemd is the init system and service manager for the majority of Linux distributions (including Ubuntu 15.04+, Debian 8+, CentOS/RHEL 7+, and Fedora). The primary tool for managing systemd services is systemctl.
To list all loaded and active services:
systemctl list-units --type=serviceTo get a more detailed, categorized list (showing running, exited, and failed services):
systemctl list-unit-files --type=serviceTo check the status of a specific service (e.g., ssh):
systemctl status ssh.service
# or simply
systemctl status sshThis command shows whether the service is active (running), enabled (to start on boot), and its recent log entries.
Using service and ps#
On older systems using SysVinit, or as a complementary method, you can use:
-
The
servicecommand: Lists the status of all services.service --status-all -
The
pscommand: Shows all running processes. This is a lower-level way to see what's executing.ps auxYou can combine it with
grepto search for specific services.ps aux | grep mysql
Understanding Service States#
When using systemctl, you'll encounter these key states:
- enabled: The service is configured to start automatically at boot.
- disabled: The service is configured not to start automatically at boot.
- active (running): The service is currently running.
- inactive (dead): The service is currently stopped.
- static: The service cannot be enabled/disabled on its own, as it is meant to be a dependency of other services.
The goal is to have services you don't need in the disabled and inactive states.
How to Disable a Service#
Disabling a service is a two-step process: stop it now, and prevent it from starting on the next boot.
1. Stopping the Service (Immediate Effect)#
This command halts the service immediately until the next reboot or until someone starts it manually.
sudo systemctl stop service_nameReplace service_name with the actual name of the service (e.g., apache2, bluetooth).
2. Disabling the Service (Prevents Auto-start)#
This command removes the service from the list of processes that start automatically at boot time.
sudo systemctl disable service_name3. The --now Flag#
You can combine the stop and disable commands into one line for convenience:
sudo systemctl disable --now service_nameHow to Remove (Uninstall) a Service#
Disabling a service leaves its software package installed on your disk. If you are sure you will never need the service again, you can completely remove it by uninstalling the package that provided it.
-
Find the package that owns the service. On Debian/Ubuntu-based systems, use
dpkg:dpkg -S /lib/systemd/system/service_name.serviceOn Red Hat/CentOS/Fedora-based systems, use
rpm:rpm -qf /usr/lib/systemd/system/service_name.service -
Remove the package. On Debian/Ubuntu-based systems, use
apt:sudo apt purge package_nameOn Red Hat/CentOS/Fedora-based systems, use
dnf(oryumon older versions):sudo dnf remove package_nameThe
purgecommand on Debian/Ubuntu systems is preferred as it also removes configuration files.
Common Services You Might Consider Disabling#
apache2/httpd: The Apache web server. Disable if you are not hosting a website.mysql/mariadb: Database servers. Disable if no applications on your system use them.cups: The printing service. Disable if you never print from this machine.bluetooth: The Bluetooth daemon. Disable if your machine has no Bluetooth hardware or you don't use it.avahi-daemon: A zero-configuration networking (Zeroconf) service that allows for easy network discovery. Often unnecessary for simple desktop or server use and can be a minor security concern.whoopsie: An error reporting service on Ubuntu. Can be disabled if you don't want to send crash reports to Canonical.
Remember: Always research what a service does before disabling it!
A Practical Walkthrough: Example with Apache#
Let's say you have a server where the Apache web server is running, but you've switched to using Nginx.
-
Identify: Check if Apache (
apache2on Debian/Ubuntu,httpdon CentOS/RHEL) is running.systemctl status apache2 # Output should show 'active (running)' and 'enabled' -
Disable and Stop: Use the combined command to stop it now and prevent it from starting on boot.
sudo systemctl disable --now apache2 -
Verify: Check the status again.
systemctl status apache2 # Output should now show 'inactive (dead)' and 'disabled' -
(Optional) Remove: If you're sure you won't need Apache anymore, find the package name and remove it.
- On Ubuntu:
dpkg -S /lib/systemd/system/apache2.service # This will likely return 'apache2' sudo apt purge apache2 apache2-utils
- On Ubuntu:
Conclusion#
Taking control of the services running on your Linux system is a fundamental aspect of good system administration and security hygiene. By following the steps outlined in this guide—identifying, understanding, disabling, and optionally removing unnecessary services—you can significantly reduce your system's attack surface, free up valuable resources, and create a cleaner, more predictable computing environment.
Start small, be cautious, and always research before you disable. Happy optimizing!
References#
- systemctl Man Page - The official manual page for the
systemctlcommand. - The Linux Documentation Project: Services - General information about services and runlevels.
- Ubuntu Server Guide: Services - Ubuntu-specific documentation on service management.
- Red Hat System Administrator's Guide: Managing Services - Red Hat and CentOS documentation for systemd.