Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

How to Enable and Disable System Services on Linux

Published

Linux

System services are critical background processes that support networking, printing, security, and a range of other essential operations on your Linux system. By enabling or disabling these services, you control what runs at startup, which helps optimize both system performance and security. This comprehensive guide explains how you can manage system services using different init systems, with a focus on systemd, which is the default for most modern Linux distributions.

You will learn how to list, enable, disable, start, and stop services, as well as best practices for verifying and troubleshooting your changes. By following these steps, you will have the knowledge to manage system services confidently and efficiently.

Prerequisites

  • Access to a Linux system with administrator (sudo) privileges
  • Familiarity with basic terminal commands
  • Knowledge of the service name you want to manage (for example, ssh, cups, or firewalld)

Introduction to System Services and Init Systems

A system service (or daemon) is a background program that supports core system functions, such as networking, printing, or firewalls. The init system, which starts during system boot, manages these services. Most modern Linux distributions use systemd, while older systems may use SysVinit or Upstart. Managing these services allows you to control system behavior, enhance security, and troubleshoot issues.

Identify Your Init System

Run the following command to determine which init system your Linux system uses:

ps -p 1 -o comm=

The output displays the name of the primary init process, such as systemd, init, or upstart.

Note: Most recent distributions, including Ubuntu, Debian, Fedora, and CentOS, use systemd by default.

List All Available Services (systemd)

List all service unit files and their enablement state:

systemctl list-unit-files --type=service

This command displays each service and whether it is enabled, disabled, static, or masked.

To see which services are currently running, execute:

systemctl list-units --type=service

Enable a Service (systemd)

Enable a service to start it automatically at boot:

sudo systemctl enable servicename

Replace servicename with the name of the service, such as ssh, cups, or firewalld.

To start the service immediately, use:

sudo systemctl start servicename

Enabling and starting a service ensures that it runs now and after every reboot.

Disable a Service (systemd)

Prevent a service from starting automatically at boot:

sudo systemctl disable servicename

This command only affects future boots.

To stop the service right away, run:

sudo systemctl stop servicename

Warning: Disabling critical services—such as networking, system logging, or device management—can disrupt system operations. Always verify a service’s function before disabling it.

Check the Status of a Service (systemd)

View a service’s status, including whether it is running and recent log output:

systemctl status servicename

Inspect the output for information on uptime, errors, and logs.

Enable or Disable Multiple Services (systemd)

Manage several services in a single command by listing their names:

sudo systemctl enable ssh cups
sudo systemctl disable bluetooth avahi-daemon

Mask and Unmask Services (systemd)

Mask a service to prevent it from being started manually or automatically:

sudo systemctl mask servicename

Masking is useful for services that must not run for security or policy reasons.

To restore normal operation, unmask the service:

sudo systemctl unmask servicename

Managing Services on SysVinit or Upstart Systems

Older Linux distributions may use SysVinit or Upstart. Use these commands if your system does not use systemd.

For SysVinit:

Enable or disable a service at boot:

sudo update-rc.d servicename enable
sudo update-rc.d servicename disable

Start or stop a service immediately:

sudo service servicename start
sudo service servicename stop

For Upstart:

Start or stop a service:

sudo service servicename start
sudo service servicename stop

To make changes persistent, edit the relevant Upstart job file or use initctl.

Note: Always refer to your distribution’s documentation for managing services with SysVinit or Upstart, as commands and file locations may differ.

Common Service Management Scenarios

Enable and Start SSH for Remote Access:

sudo systemctl enable ssh
sudo systemctl start ssh

Disable and Stop Bluetooth (if unused):

sudo systemctl disable bluetooth
sudo systemctl stop bluetooth

Check the Status of the Firewall:

systemctl status ufw

Reboot and Verify Service State

Reboot your system to ensure changes take effect:

sudo reboot

After the system restarts, confirm the state of your services:

systemctl status servicename

Troubleshooting and Best Practices

  • Carefully research the purpose of each service before making changes.
  • Avoid disabling services essential to networking, authentication, or system startup.
  • Use service status messages and logs to diagnose any issues after enabling or disabling a service.
  • Consider masking unwanted services for additional security.
  • If you encounter system problems after changing services, use recovery mode or a live environment to restore service functionality.

Conclusion

You can now confidently enable and disable system services on Linux using systemd and other init systems. Proper service management improves system performance, increases security, and helps tailor your system to your needs. Always verify the function of a service before making permanent changes, and test your configuration after adjustments to ensure continued stability.

Related guides

Account services are unavailable until the production backend is configured.