Identify and Disable unnecessary services on Linux Machine

In this chapter, you will learn

  1. how to stop and disable services on Ubuntu and CentOS Linux machines.

After setting up the Linux server with your favourite distros such as Ubuntu 23.10 or CentOS 8/9, there are various configurations that you need to implement to make your server secure, robust, and for faster performance. To accomplish these tasks, you must identify and disable unused and unnecessary services on your Linux server.

Here, in this article, I will explain how you can identify and disable those services.

Why it is important to stop unused services?

Services run in the background and consume system resources such as processing power and system memory. This can slow down your server's performance. However, services provide several benefits and are necessary to keep various applications running smoothly. If you determine that you are not using particular services, it's essential to stop and disable them.

In this tutorial, you will learn how to stop and disable services on Ubuntu and CentOS Linux machines.

1 List All the Services

Begin your journey by listing all the running/stopped services on your Linux machine. You can accomplish this by using the following command:

sudo service --status-all
[ - ] apache-htcacheclean [ + ] apache2 [ + ] apf-firewall [ - ] apparmor [ + ] apport [ - ] auditd [ + ] clamav-daemon [ + ] clamav-freshclam [ - ] console-setup.sh [ + ] cron [ - ] cryptdisks [ - ] cryptdisks-early [ + ] dbus [ - ] hwclock.sh [ - ] irqbalance [ - ] iscsid [ - ] keyboard-setup.sh [ - ] kmod [ - ] lvm2 [ - ] lvm2-lvmpolld [ - ] open-iscsi [ - ] open-vm-tools [ + ] plymouth [ + ] plymouth-log [ + ] procps [ - ] rsync [ - ] screen-cleanup [ - ] selinux-autorelabel [ + ] ssh [ + ] sysstat [ + ] udev [ + ] ufw [ + ] unattended-upgrades [ - ] uuidd [ - ] x11-common

In the above output, services with a [-] prefix indicate Stop/Inactive, while services with a [+] prefix indicate Enabled and Running.

2 Manage Services with systemctl command

The systemctl command interacts with the service manager, and allows you to manage services using easy command options. With systemctl, you can effortlessly start, stop, restart, reload, or disable services.

# Title Command
1 Start a service
sudo systemctl start ssh
2 Stop a service
sudo systemctl stop ssh
3 Restart a service
sudo systemctl restart ssh
4 Reload a service
sudo systemctl reload ssh
5 Enable a service
sudo systemctl enable ssh
6 Disable a service
sudo systemctl disable ssh
7 View service status
sudo systemctl status ssh

Masking and Unmasking services

A masked service cannot be started or enabled, regardless of whether it is required by some applications or services. Masking effectively locks the services.

Unmasking unlocks the services, allowing them to be started or enabled, and they become available for applications or services to use.

Mask a service:
sudo systemctl mask ssh

Unmask a service:
sudo systemctl unmask ssh

Summary

It is important to remove overload from your server by disabling services that you don't require. However, it is a bit cumbersome and confusing, as you don't know which services do what job. Just gain more information about each service and then disable them according to your requirements.