1080*80 ad

Finding Running Services in Linux with Systemd: A Quick Guide

Mastering Systemd: A Complete Guide to Checking Running Services in Linux

Effective Linux system administration hinges on knowing precisely what’s happening under the hood. Whether you’re troubleshooting performance bottlenecks, conducting a security audit, or simply maintaining a healthy server, one of the most fundamental tasks is identifying which services are currently running. On modern Linux distributions, the systemd init system provides a powerful and consistent toolset for this exact purpose.

Understanding how to query systemd is a crucial skill. It allows you to get a real-time snapshot of your system’s state, helping you manage resources and ensure stability. This guide will walk you through the essential commands you need to master service management in Linux.

Why You Need to Know What’s Running

Before diving into the commands, it’s important to understand why this knowledge is so critical:

  • Security: Unnecessary services can expand your system’s attack surface. Regularly auditing your running services helps you identify and disable anything that isn’t required, minimizing potential vulnerabilities.
  • Performance: Every running service consumes system resources like CPU and memory. If your system is slow, an unexpected or misbehaving service could be the culprit.
  • Troubleshooting: When an application fails, one of the first steps is to check if its dependent services are active and running correctly.
  • Resource Management: By understanding what’s running, you can make informed decisions about capacity planning and resource allocation.

The Essential Command: Listing All Active Units

The primary tool for interacting with systemd is the systemctl command. To get a broad overview of everything systemd is managing—not just services, but also sockets, mount points, and more—you can use the list-units command.

To focus specifically on services, you’ll want to filter by unit type.

systemctl list-units --type=service

This command will show all service units that are loaded and have tried to activate. The output includes several important columns:

  • UNIT: The name of the service unit file (e.g., sshd.service).
  • LOAD: Shows if the unit file was loaded correctly.
  • ACTIVE: The high-level state (e.g., active, inactive, failed).
  • SUB: The low-level state (e.g., running, exited, dead).
  • DESCRIPTION: A brief, human-readable description of the service.

While useful, this command shows all active services, which can include services that have run and then exited successfully. For a more precise view, you need to filter further.

How to See Only Currently Running Services

For a more focused list that shows only the services that are actively running right now, you can add the --state=running flag.

This is often the most useful command for a quick health check:

systemctl list-units --type=service --state=running

This command filters the list to only include services that are in the active state and the running sub-state. The output is a clean, concise list of processes that are currently executing on your system, making it perfect for quick diagnostics.

Checking the Status of a Specific Service

What if you don’t need a full list, but just want to know if a particular service, like the SSH server or a database, is running? For this, the systemctl status command is your best friend.

To check the detailed status of the SSH service, for example, you would use:

systemctl status sshd.service

The output of this command is incredibly rich with information:

  • It tells you if the service is loaded and active (running).
  • It shows the Main PID (Process ID) of the running service.
  • It displays the most recent log entries from journald related to that service, which is invaluable for debugging.
  • It shows whether the service is enabled or disabled, indicating if it’s configured to start automatically on boot.

Actionable Tip: Pay close attention to the line that says “Loaded: … enabled;”. A service that is “enabled” will start automatically when the system boots. If you find a service running that you don’t need, you should both stop it and disable it to prevent it from starting again.

  • To stop a running service: sudo systemctl stop <service-name>
  • To prevent it from starting on boot: sudo systemctl disable <service-name>

Listing All Available Services (Not Just Active Ones)

Sometimes you need to see every possible service available on the system, regardless of whether it’s running or not. This is useful for discovering what software is installed and can be enabled.

systemctl list-unit-files --type=service

This command provides a list of all service units installed on the system and their state:

  • enabled: The service is configured to start at boot.
  • disabled: The service will not start at boot.
  • static: The service can’t be enabled directly but is often started as a dependency of another service.
  • masked: The service is completely disabled and cannot be started manually or as a dependency.

Security Best Practices for Managing Linux Services

Mastering these commands is the first step. Applying them to secure your system is the next.

  1. Conduct Regular Audits: At least once a month, run systemctl list-units --type=service --state=running and review the output. Compare it to a list of known, required services. Investigate anything you don’t recognize.

  2. Apply the Principle of Least Privilege: If a service isn’t absolutely necessary for the system’s function, disable it. For example, if you are not using your server as a print server, there’s no reason for the CUPS service (cups.service) to be running.

  3. Check for Failed Services: A failed service can indicate a misconfiguration, a security issue, or a corrupted application. Use the following command to quickly find any services that have failed to start:

    systemctl --failed --type=service
    

By integrating these systemctl commands into your regular workflow, you gain deeper insight and control over your Linux environment, leading to more secure, stable, and efficient systems.

Source: https://www.tecmint.com/list-all-running-services-under-systemd-in-linux/

900*80 ad

      1080*80 ad