Mastering the systemctl Command in Linux: A Complete Guide

Managing system services efficiently is a crucial skill for Linux users, especially system administrators and developers. The systemctl command in Linux is an essential tool that allows you to start, stop, restart, enable, and disable services with ease. Since systemd is the default service manager on most modern Linux distributions—including Rocky Linux, Ubuntu, CentOS, Fedora, and Debian—learning how to use systemctl effectively will enhance your ability to control system processes.

In this guide, we’ll walk you through the systemctl command in Linux, explaining its key functions, usage examples, and best practices.

🚀 For a hands-on tutorial, check out our YouTube video:


What is the systemctl Command in Linux?

The systemctl command in Linux is a command-line tool used to interact with systemd, the service manager responsible for system initialization, process monitoring, and service control. With systemctl, you can:

✅ Start, stop, restart, and check the status of services.
✅ Enable or disable services to start on boot.
✅ Monitor system processes and logs for troubleshooting.

What Runs First on System Boot?

At system startup, systemd is the first process that runs and is assigned PID 1 (Process ID 1). It then initializes all other services.

To check this, run:

ps -p 1

You can also visualize system processes with:

pstree 1

Commonly Used systemctl Commands

Let’s go over the most frequently used systemctl commands in Linux, using Apache (httpd) as an example service.

Checking Service Status

To check if a service is running, use:

systemctl status httpd

✅ This helps verify whether Apache is active or has failed.

Starting and Stopping Services

To start a service:

systemctl start httpd

✅ Use this after installing Apache to begin serving web pages.

To stop a service:

systemctl stop httpd

✅ Useful for performing maintenance or updates.

Restarting Services

systemctl restart httpd

✅ Required after configuration changes to apply new settings.

Enabling and Disabling Services on Boot

To enable Apache to start automatically on boot:

systemctl enable httpd

To disable it:

systemctl disable httpd

Advanced systemctl Commands

Checking Active Services

To check if a service is running without detailed output:

systemctl is-active httpd

To list all active services:

systemctl list-units --type=service

Masking and Unmasking Services

To prevent a service from starting, even manually:

systemctl mask httpd

To re-enable it:

systemctl unmask httpd

Rebooting or Halting the System

To reboot:

systemctl reboot

To halt without restarting:

systemctl halt

Understanding systemd Unit Files

Systemd uses unit files to manage services. These files are stored in:
📂 /etc/systemd/system/ – Custom and user-defined unit files.
📂 /lib/systemd/system/ – Default unit files installed by packages.

To find a unit file location:

systemctl show -p FragmentPath httpd

Working with Logs

To check service logs using journalctl:

journalctl -u httpd

✅ This helps diagnose issues that are not immediately visible through systemctl status.


FAQs

1️⃣ What is the difference between systemctl and service commands?

The service command is an older method used in SysVinit systems, while systemctl is part of systemd, which is more powerful and modern.

2️⃣ How do I check all running services using systemctl?

Run:

systemctl list-units --type=service

3️⃣ How do I restart multiple services at once?

You can restart multiple services by running:

systemctl restart httpd mysqld sshd

4️⃣ Can I use systemctl on non-systemd Linux distributions?

No, systemctl only works on systemd-based distributions like Rocky Linux, Ubuntu, CentOS, and Fedora.

5️⃣ What should I do if a service fails to start?

Check the status:

systemctl status <service-name>

Then view logs:

journalctl -u <service-name>

Conclusion

Mastering the systemctl command in Linux is essential for efficient service management. Whether you’re managing servers, deploying applications, or troubleshooting issues, these commands help you keep services running smoothly.

📌 Want a step-by-step walkthrough? Watch our YouTube tutorial here


See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs







Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.