Disabling the unit

You can also achieve a similar effect by disabling the unit. Disabling a unit removes the symbolic links to the unit files, preventing it from being started.

sudo systemctl disable <unit_name>

Explanation:

  • The ‘systemctl disable‘ command removes symbolic links related to the specified unit, preventing it from being started.
  • This is an alternative method to achieve a similar effect to masking.

For example:

sudo systemctl disable nginx.service

Output:

Disabling unit

Output shows disabled that the unit has been disabled successfully.

To re-enable the unit :

sudo systemctl enable <unit_name>

Above command re-enables the unit and for more clarity refer to the below example:

sudo systemctl enable nginx.service

Re-enabling unit

Output shows that the unit has been re-enabled.

How to mask a systemd unit in Linux?

Systemd is a system and service manager for Linux operating systems, providing a range of functionalities for managing system processes. In some cases, you may want to hide or disable a systemd unit to prevent it from starting automatically. This process is known as “masking” a systemd unit. In this article, we’ll explore the steps to mask a systemd unit in Linux.

Similar Reads

What is Systemd?

Systemd is a suite of system management daemons, libraries, and utilities designed to centralize the management of system services. It replaces the traditional System V init scripts and provides features like the parallel startup of system services, on-demand activation of daemons, and dependency-based service control....

Systemd Units

Systemd units are configuration files that describe how a service, device, mount point, or other aspects of the system should be managed by systemd. Units are defined with files having extensions like .service, .socket, .mount, etc. They are located in directories such as /etc/systemd/system/ or /usr/lib/systemd/system/....

Method 1: Masking a Systemd Unit

Masking a systemd unit means making it impossible to start the unit, either manually or during system boot. This is achieved by creating a symlink from the unit file to /dev/null. The following steps demonstrate how to mask a systemd unit:...

Method 2: Disabling the unit

You can also achieve a similar effect by disabling the unit. Disabling a unit removes the symbolic links to the unit files, preventing it from being started....

Method 3: Renaming the Unit File:

sudo mv /etc/systemd/system/ /etc/systemd/system/.backupsudo systemctl daemon-reload...

Masking Systemd Units in Linux: FAQs

What is masking a systemd unit?...

Conclusion

Masking a systemd unit in Linux is a straightforward process that involves stopping the unit and creating a symbolic link to /dev/null. This prevents the unit from starting automatically during system boot or when manually invoked. Always exercise caution when masking units, as it may impact system functionality, and only mask units that you are certain should be disabled....