Control Firewall, OpenSSH & Other System Services with systemctl (Day 8 of 30)

Table of Contents Introduction Understanding systemctl Basic operations (start, stop, status, enable, disable, restart, reload) Advanced operations (mask, unmask) Practical Examples Examples using common services like sshd, firewalld, httpd Summary 1. Introduction Managing system services is a core responsibility for any Linux sysadmin or power user. On RHEL 9, which uses systemd as its init system, the systemctl command is your gateway to starting, stopping, and configuring services (daemons). Learning a few essential systemctl commands will let you control services easily—whether you're running a web server, SSH daemon, or the firewall. In this article, we’ll cover the basics of systemctl for RHEL 9 (most of it works the same on other modern distros). By the end, you’ll know how to start/stop services, enable them at boot, check their status, and even disable them if needed. Let’s dive in and get you feeling confident managing your system’s services! 2. Understanding systemctl systemctl is the main command-line tool to interact with systemd (the service manager on RHEL 9). It can start or stop services immediately, query their status, and configure whether they run at boot. Here are the basic systemctl operations you’ll use every day: systemctl start — Start the specified service right now. For example, systemctl start sshd will launch the SSH server. systemctl stop — Stop a running service immediately. For example, systemctl stop httpd stops the Apache web server. systemctl status — Check the status of a service. This shows if it's active (running), its process ID, and recent log entries. systemctl restart — Restart a service (stop, then start). Use this after changing a service’s configuration. systemctl reload — Reload a service’s configuration without fully stopping it. Only works if the service supports reloading (e.g. it reloads settings without disconnecting clients). systemctl enable — Configure the service to start automatically at boot. After enabling, the service will run every time the system starts (unless masked or disabled). systemctl disable — Stop a service from starting automatically at boot. This does not stop a running service immediately, but it prevents future automatic starts. These commands cover the most common service management tasks. You can also combine them in scripts or use systemctl status followed by --no-pager to get a full output. Advanced operations: mask and unmask Two more advanced systemctl commands are mask and unmask. Masking a service ensures it cannot be started (even manually or by dependencies). For example, systemctl mask links the service unit to /dev/null, making it effectively disabled. This is useful for critical services you want to prevent from ever running (e.g. systemctl mask sshd if you never want SSH on). To undo this, use systemctl unmask , which restores the service so you can start or enable it again. Use these with care, as masking prevents any start of that service. 3. Practical Examples In RHEL 9, common services you’ll manage include sshd (the OpenSSH server), firewalld (the firewall daemon), and httpd (Apache). Here’s how systemctl works with these: sshd (OpenSSH Server): The SSH service is usually called sshd on RHEL. Check status: systemctl status sshd will show if the SSH server is running. Start SSH: systemctl start sshd. Now you can connect via SSH. Enable at boot: systemctl enable sshd ensures SSH starts automatically after a reboot. After editing /etc/ssh/sshd_config, apply changes with systemctl restart sshd. firewalld (Firewall daemon): This is RHEL’s default firewall service. Check status: systemctl status firewalld shows if it’s active. Start firewall: systemctl start firewalld. Enable at boot: systemctl enable firewalld. Reload rules: After changing zones or rules, use systemctl reload firewalld to apply them without dropping connections. httpd (Apache Web Server): If you host a website, httpd is the Apache service. Start web server: systemctl start httpd. Enable at boot: systemctl enable httpd. Check status: systemctl status httpd. Restart after config change: systemctl restart httpd. As you can see, the commands are consistent across services: just replace with the name (e.g. sshd, firewalld, httpd). This makes managing services straightforward. 4. Summary Controlling services on RHEL 9 is straightforward with systemctl. In this article, we covered how to: Start, stop, and restart services with systemctl start/stop/restart . Check status of a service with systemctl status . Enable or disable services at boot using systemctl enable/disable . Reload a service’s configuration (if supported) with systemctl reload . Mask and unmask services (systemctl mask/unmask ) for advanced use. These commands form a complete toolkit for everyday service manag

Apr 27, 2025 - 17:00
 0
Control Firewall, OpenSSH & Other System Services with systemctl (Day 8 of 30)

Table of Contents

  1. Introduction
  2. Understanding systemctl
    • Basic operations (start, stop, status, enable, disable, restart, reload)
    • Advanced operations (mask, unmask)
  3. Practical Examples
    • Examples using common services like sshd, firewalld, httpd
  4. Summary

1. Introduction

Managing system services is a core responsibility for any Linux sysadmin or power user. On RHEL 9, which uses systemd as its init system, the systemctl command is your gateway to starting, stopping, and configuring services (daemons). Learning a few essential systemctl commands will let you control services easily—whether you're running a web server, SSH daemon, or the firewall. In this article, we’ll cover the basics of systemctl for RHEL 9 (most of it works the same on other modern distros). By the end, you’ll know how to start/stop services, enable them at boot, check their status, and even disable them if needed. Let’s dive in and get you feeling confident managing your system’s services!

2. Understanding systemctl

systemctl is the main command-line tool to interact with systemd (the service manager on RHEL 9). It can start or stop services immediately, query their status, and configure whether they run at boot. Here are the basic systemctl operations you’ll use every day:

  • systemctl start Start the specified service right now. For example, systemctl start sshd will launch the SSH server.
  • systemctl stop Stop a running service immediately. For example, systemctl stop httpd stops the Apache web server.
  • systemctl status Check the status of a service. This shows if it's active (running), its process ID, and recent log entries.
  • systemctl restart Restart a service (stop, then start). Use this after changing a service’s configuration.
  • systemctl reload Reload a service’s configuration without fully stopping it. Only works if the service supports reloading (e.g. it reloads settings without disconnecting clients).
  • systemctl enable — Configure the service to start automatically at boot. After enabling, the service will run every time the system starts (unless masked or disabled).
  • systemctl disable — Stop a service from starting automatically at boot. This does not stop a running service immediately, but it prevents future automatic starts.

These commands cover the most common service management tasks. You can also combine them in scripts or use systemctl status followed by --no-pager to get a full output.

Advanced operations: mask and unmask

Two more advanced systemctl commands are mask and unmask. Masking a service ensures it cannot be started (even manually or by dependencies). For example, systemctl mask links the service unit to /dev/null, making it effectively disabled. This is useful for critical services you want to prevent from ever running (e.g. systemctl mask sshd if you never want SSH on). To undo this, use systemctl unmask , which restores the service so you can start or enable it again. Use these with care, as masking prevents any start of that service.

3. Practical Examples

In RHEL 9, common services you’ll manage include sshd (the OpenSSH server), firewalld (the firewall daemon), and httpd (Apache). Here’s how systemctl works with these:

  • sshd (OpenSSH Server): The SSH service is usually called sshd on RHEL.

    • Check status: systemctl status sshd will show if the SSH server is running.
    • Start SSH: systemctl start sshd. Now you can connect via SSH.
    • Enable at boot: systemctl enable sshd ensures SSH starts automatically after a reboot.
    • After editing /etc/ssh/sshd_config, apply changes with systemctl restart sshd.
  • firewalld (Firewall daemon): This is RHEL’s default firewall service.

    • Check status: systemctl status firewalld shows if it’s active.
    • Start firewall: systemctl start firewalld.
    • Enable at boot: systemctl enable firewalld.
    • Reload rules: After changing zones or rules, use systemctl reload firewalld to apply them without dropping connections.
  • httpd (Apache Web Server): If you host a website, httpd is the Apache service.

    • Start web server: systemctl start httpd.
    • Enable at boot: systemctl enable httpd.
    • Check status: systemctl status httpd.
    • Restart after config change: systemctl restart httpd.

As you can see, the commands are consistent across services: just replace with the name (e.g. sshd, firewalld, httpd). This makes managing services straightforward.

4. Summary

Controlling services on RHEL 9 is straightforward with systemctl. In this article, we covered how to:

  • Start, stop, and restart services with systemctl start/stop/restart .
  • Check status of a service with systemctl status .
  • Enable or disable services at boot using systemctl enable/disable .
  • Reload a service’s configuration (if supported) with systemctl reload .
  • Mask and unmask services (systemctl mask/unmask ) for advanced use.

These commands form a complete toolkit for everyday service management on RHEL 9. Practice using them with services like sshd, firewalld, and httpd, and you’ll soon feel fully in control of your system’s daemons. Happy administering!