Enabling and Disabling Services

You can use the systemctl command to enable or disable a service from starting when the system boots, for example:

sudo systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

The enable command activates a service by creating a symbolic link for the lowest-level system-state target at which the service starts. In the previous example, the command creates the symbolic link httpd.service for the multi-user target.

Note:

To start the service at the same time you enable it, include the --now option in the command. For example: sudo systemctl enable --now httpd

Disabling a service removes the symbolic link:

sudo systemctl disable httpd
Removed /etc/systemd/system/multi-user.target.wants/httpd.service.

To check whether a service is enabled, use is-enabled subcommand as shown in the following examples:

sudo systemctl is-enabled httpd
disabled
sudo systemctl is-enabled sshd
enabled

After running the systemctl disable command, the service can still be started or stopped by user accounts, scripts, and other processes. However, if you need to ensure that the service might be started inadvertently, for example, by a conflicting service, then use the systemctl mask command as follows:

sudo systemctl mask httpd
Created symlink from '/etc/systemd/system/multi-user.target.wants/httpd.service' to '/dev/null'

The mask command sets the service reference to /dev/null. If you try to start a service that has been masked, you will receive an error as shown in the following example:

sudo systemctl start httpd
Failed to start httpd.service: Unit is masked.

To relink the service reference back to the matching service unit configuration file, use the systemctl unmask command:

sudo systemctl unmask httpd

For more information, see the systemctl(1) manual page.