Announcement

Collapse
No announcement yet.

How to Mask a Service using systemctl Command

Collapse
X
Collapse
  •  

  • How to Mask a Service using systemctl Command

    The systemctl is a command line utility used to manage system services. It has a variety of options to manage the service on Linux, such as starting a service, stopping it, enabling, and disabling it. There is another option called a mask.
    Masking a systemd service means the service is disabled and cannot be enabled, even by the system or on manual command. Masking is a stronger form of disabling.

    In this guide, I will walk you through how to mask a service on Linux using systemctl, and how to unmask it. Moreover, I will cover key differences between a masked service and a disabled service.

    Warning: On Linux, the services are interdependent. Since masking the service disables it and prohibits any activation, therefore use it carefully.

    Before going further, let’s first understand the mechanism behind the masked service.

    What is a Masked Service

    A masked service is a permanently disabled service that prevents it from being enabled by the system or system administrator. System administrators generally use the mask option to deactivate the malfunctioned or conflicting services. However, it is recommended to use this option with caution, as masking a crucial system service may bring hurdles in booting the system.

    How to List Masked Services

    To list masked services on Linux, use the list-units option with the state mentioned masked.

    systemctl list-units --state=masked




    How to Mask a Service

    The systemctl command can be used to mask any service with the mask option. The general syntax of the command is mentioned below.

    sudo systemctl mask [Service-Name]


    The mask option in the above syntax essentially makes a symbolic link to the service in the /etc/systemd/system.

    One or more services can also be mentioned, separated by a space.

    Let’s mask the SSH service using the above syntax.

    sudo systemctl mask ssh.service




    To check the status of a masked service, use the –state= option with systemctl list-units.



    If you attempt to start the service, you will receive an output saying that the unit is masked.



    Note: You cannot mask a service created in the /etc/systemd/system directory. Because services in this directory are essential for system operations, masking them can harm normal system functionality. However, disabling these services is equivalent to masking them.

    How to Mask a Service Temporarily

    A service can be masked untill the next boot by using the –runtime option.

    sudo systemctl mask [Service-Name] --runtime




    It creates a symbolic link of the service in the /run/systemd/system directory. If the symbolic link of the service is already present in the directory, then the service is designed to be masked temporarily.

    How to Unmask a Service

    Use the systemctl command with the unmask option to remove the mask restrictions. This command will not accept the path of the service, therefore, only service names are required to be mentioned.

    sudo systemctl unmask [Service-Name]


    You may need to reboot the system after unmasking the service.

    Difference between a Masked Service and a Disabled Service

    A disabled service can be enabled and started by the system and on manual commands. However, the masked service cannot be enabled, neither by the system nor by manual interaction.

    When a service is made disabled, a symbolic link that is created in the /etc/systemd/system directory is removed, and the service does not activate on boot. But it can be activated by the dependent services.

    On the other hand, the masked service is linked to the /dev/null which makes it permanently unusable.

    Note that the /dev directory contains the files of the block devices. The /dev/null is a virtual device that removes anything written to it. It is generally used to discard output from stdout and stderr.

    Conclusion

    If you want to make any service permanently disabled, then use the systemctl mask command. A masked service cannot be enabled even by the system. In this guide, I covered how to mask a service permanently, and temporarily. Moreover, we also mentioned a method to unmask a service and the key differences between a masked and a disabled service.





    More...
      Posting comments is disabled.

    Categories

    Collapse

    Article Tags

    Collapse

    There are no tags yet.

    Latest Articles

    Collapse

    • Unlocking Data Science Potential Understanding Machine Learning and Data Analysis with JupyterLab
      by Kasimba



      by George Whittaker


      Introduction

      In recent years, JupyterLab has rapidly become the tool of choice for data scientists, machine learning (ML) practitioners, and analysts worldwide. This powerful, web-based integrated development environment (IDE) provides a flexible and interactive workspace for performing data analysis, machine learning, and visualization, making it indispensable for professionals and enthusiasts...
      10-29-2024, 04:00 PM
    • Hardening Linux Servers Against Threats and Attacks
      by Kasimba



      by George Whittaker


      Introduction

      Linux servers are known for their reliability and security, which has made them popular in both enterprise and individual deployments. However, no system is impervious to attacks. With cyber threats evolving constantly, server administrators must adopt proactive measures to secure their systems against vulnerabilities and attacks. This guide dives into a range of hardening techniques...
      10-25-2024, 01:50 PM
    • Crafting a Custom Linux Kernel for Your Embedded Projects
      by Kasimba



      by George Whittaker


      Introduction

      Embedded systems have become a cornerstone of modern technology, powering everything from IoT devices to automotive control systems. These specialized systems rely on software that is lightweight, efficient, and highly optimized for specific hardware configurations. At the heart of this software stack lies the Linux kernel, which is widely used in embedded devices due to its...
      10-23-2024, 05:30 AM
    • The Evolution of Linux Package Management and Its Impact on Modern Computing
      by Kasimba



      by George Whittaker


      Introduction

      If you’ve ever used a modern Linux distribution, you’ve likely experienced the convenience of installing and updating software with a single command. Package managers, the tools behind this ease of use, have become a cornerstone of the Linux ecosystem, providing a structured and efficient way to manage software. However, the history of Linux package management is a long...
      10-21-2024, 10:23 PM
    • A Simple Overview of GRUB Bootloader Configuration
      by Kasimba



      by George Whittaker


      Understanding the intricacies of the Linux boot process and the GRUB bootloader configuration is essential for system administrators, developers, and Linux enthusiasts who want to harness the full potential of their operating systems. This article provides an exploration of the boot sequence in Linux systems, highlighting the role of GRUB and offering practical insights into its configuration and customization....
      10-17-2024, 09:00 PM
    • Wanted: Skilled cybersecurity it pros
      by Kasimba
      Be Prepared. Get Skilled Today. Use code: OCT24CYBER to Save 40% on Cybersecurity Courses & Certifications Use code: OCT24 to Save 30% on all other eLearning courses & certifications *Offer ends October 22, 2024 Save Now at LF Education

      The post WANTED: SKILLED CYBERSECURITY IT PROS appeared first on Linux.com.



      More...
      10-14-2024, 09:40 PM
    Working...
    X