disable unnecessary services

How to Disable Unnecessary Services in Linux

Unnecessary services consume CPU processing and memory in Linux. So it is important to find and disable unnecessary services in Linux. Many of these services are created and started when we install an application. However, over time when stop using certain applications or even delete them, some services continue to run, taking up processing power. They can increase server load, decrease performance and increase costs. So it is advisable to disable or remove services that you don’t require, regularly. Here is how to disable unnecessary services in Linux.


How to Disable Unnecessary Services in Linux

Here are the steps to disable unnecessary services in Linux. It is useful if you find your server is getting overloaded and you need to free up some processing power and memory.


List All services

Here is the command to list all services in Linux.

# sudo service --status-all
 [ + ]  acpid
 [ + ]  apache-htcacheclean
 [ + ]  apache2
 [ + ]  apparmor
 [ + ]  apport
 [ + ]  atd
 [ - ]  console-setup.sh
 [ + ]  cron
 [ - ]  cryptdisks
 ...

It will display list of all services present in your system, each with a + or – symbol at its beginning. If there is a + sign at the beginning it means the service is running. If there is a – sign at its beginning, it means the service is inactive.

If you don’t need to a particular service then here is the command to disable it

# sudo service disable <service_name>

Here is the example to disable particular service such as apache2.

# sudo service disable apache2

Now if you list all services on your system, you will see a – sign in front of apache2.

If you want to see the status of a specific service, you can also use the following command for it.

# sudo service <service_name> status

Here is an example to check status of apache2 service.

# sudo service apache2 status

If you are using any of the new Linux versions, you will realize that it doesn’t use System V but Systemd, managed by systemctl command.

Here are the key commands to manage services in Linux. You can easily get list of failed processes with the following command.

$ systemctl --failed

Here is the command to list all services that are running.

$ systemctl

Here is the command to start a service such as apache2.

$ sudo systemctl <service_name> start #syntax
$ sudo systemctl apache2 start #example

You may also use service command for the same purpose.

$ sudo service <service_name> start #syntaxt
$ sudo service apache2 start #example

Similarly, you can stop a service by replacing start in the above commands with stop.

#syntax
$ sudo systemctl <service_name> stop
OR
$ sudo service <service_name> stop

#example
$ sudo systemctl apache2 stop
OR
$ sudo service apache2 stop

Here is the command to restart service.

#syntax
$ sudo systemctl <service_name> restart
OR
$ sudo service <service_name> restart

#example
$ sudo systemctl apache2 restart
OR
$ sudo service apache2 restart


Disable Service

Here is the command to disable service using systemctl or service command.

#syntax
$ sudo systemctl <service_name> disable
OR
$ sudo service <service_name> disable


#example
$ sudo systemctl apache2 disable
OR
$ sudo service apache2 disable

Similarly, here is the command to enable service using systemctl or service command.

#syntax
$ sudo systemctl <service_name> enable
OR
$ sudo service <service_name> enable


#example
$ sudo systemctl apache2 enable
OR
$ sudo service apache2 enable

You can use top command to get an idea of which running service consumes how much CPU usage and memory, and accordingly decide to disable it.

In this article, we have looked at how to find and disable unnecessary services in Linux. It is a good practice to identify and remove unnecessary services on your system, from time to time to free up CPU power and memory. This will help improve performance of your server, as well as save server costs. Otherwise, you will need to unnecessarily upgrade your server thinking that they are overloaded.

Also read:

Top SFTP Command Examples
How to Use Journalctl Command in Linux
How to Grep Log File Within Specific Time Period
Top Yum Command Examples in Linux
How to Password Protect Folders in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *