Linux Package Managers & systemctl Explained: apt, dnf, pacman & Service Management

Package managers and systemctl are two of the most essential tools in Linux. One controls what software lives on your system — the other controls whether it is running. For ethical hackers, penetration testers, and system administrators, mastering both is foundational to working effectively in any Linux environment.
Once you understand the Linux file system, the next critical skill is knowing how to install and manage software — and how to control the services running on a system. In Linux, this is handled by two core tools: package managers (which install, update, and remove software packages) and systemctl (which starts, stops, and manages background services via the systemd init system).
These tools are used daily by system administrators, DevOps engineers, and — critically for this series — ethical hackers. During a penetration test, a tester might install a new reconnaissance tool via a package manager or check whether a vulnerable service like Apache or SSH is running using systemctl. Understanding both tools deeply is not optional — it is the baseline for Linux-based security work.

Linux package managers — what they are and how they work

A Linux package manager is a command-line tool that automates the process of installing, updating, configuring, and removing software packages from official repositories. Instead of manually downloading binaries and resolving dependencies, a package manager handles everything in a single command — fetching the software, verifying its integrity, installing dependencies, and registering the package with the system.
Different Linux distributions use different package managers. The three most important for cybersecurity professionals are:

Debian_Ubuntu: APT (Advanced Package Tool)

The default package manager for Debian-based systems, including Ubuntu, Kali Linux, and Parrot OS — the most common ethical hacking platforms.

Uses .deb packages from /etc/apt/sources.list

RHEL_Fedora_CentOS: DNF (Dandified YUM)

Default manager for Red Hat Enterprise Linux, Fedora, and CentOS. Widely used in enterprise server environments and cloud infrastructure.

Uses .rpm packages from configured repositories

Arch Linux_Manjaro: Pacman (Package Manager)

The rolling-release package manager for Arch Linux and derivatives. Known for its speed, simplicity, and access to the Arch User Repository (AUR).

Uses .pkg.tar.zst packages — rolling release model

Since Kali Linux — the most widely used ethical hacking distribution — is Debian-based, apt is the package manager you will use most often in penetration testing work. Every tool in the series from this point forward — Nmap, Metasploit, Burp Suite, Wireshark — is installed and updated via apt on Kali.

Essential package manager commands

Actionapt (Debian/Ubuntu/Kali)dnf (RHEL/Fedora)pacman (Arch)
Update package listapt updatednf check-updatepacman -Sy
Upgrade all packagesapt upgradednf upgradepacman -Syu
Install a packageapt install nmapdnf install nmappacman -S nmap
Remove a packageapt remove nmapdnf remove nmappacman -R nmap
Search for a packageapt search nmapdnf search nmappacman -Ss nmap
Show package infoapt show nmapdnf info nmappacman -Si nmap

Systemctl – Managing Linux Services

systemctl is the command-line interface to systemd — the init system and service manager used by the majority of modern Linux distributions, including Ubuntu, Debian, Fedora, Kali Linux, and CentOS. It controls units — most commonly services (background processes like web servers, SSH daemons, databases, and firewalls) — allowing administrators to start, stop, enable, disable, and inspect them.
For ethical hackers, systemctl is essential in two scenarios: on your own Kali machine (managing tools like the PostgreSQL database required by Metasploit, or the Apache web server for phishing simulations), and on compromised target systems (enumerating running services to map the attack surface and identify exploitable processes).

Service Control Commands

systemctl start apache2

Start a service immediately — does not persist across reboots

systemctl stop apache2

Stop a running service immediately

systemctl restart apache2

Stop then immediately restart a service — useful after config changes

systemctl reload apache2

Reload configuration without stopping the service — less disruptive than a restart

systemctl enable apache2

Configure the service to start automatically on every boot

systemctl disable apache2

Prevent service from starting automatically on boot

systemctl status apache2

Display detailed status — running state, PID, recent log lines, exit codes

systemctl list-units –type=service

List all active service units on the system – critical for enumeration

$ systemctl status ssh

● ssh.service – OpenBSD Secure Shell server

Loaded: loaded (/lib/systemd/system/ssh.service; enabled)

Active: active (running) since Mon 2026-03-30 09:14:22 UTC

Process: ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)

Main PID: 1042 (sshd)

Tasks: 1 (limit: 4915)

CGroup: /system.slice/ssh.service

The combination of systemctl enable and systemctl start is the standard way to both start a service immediately and ensure it persists across reboots. Running only start without enable is a common mistake — the service disappears after the next reboot.

Real-world scenario:
Setting up Metasploit on Kali Linux

When an ethical hacker sets up their Kali Linux environment for a penetration testing engagement, both a package manager and systemctl are used in a standard workflow. Here is exactly what that looks like in practice:

Real-world: preparing Metasploit on Kali Linux (Authorized lab environment)

Step 1 — Update

Run sudo apt update && sudo apt upgrade -y to refresh the package list and upgrade all installed tools. Skipping this step means working with outdated tool versions that may have known bugs or missed capabilities.

Step 2 — Install

Run sudo apt install metasploit-framework to install Metasploit. apt automatically resolves and installs all dependencies — Ruby runtime, required gems, and supporting libraries — without any manual intervention.

Step 3 — Database

Metasploit requires PostgreSQL. Run sudo systemctl start postgresql to start the database service, then sudo systemctl enable postgresql so it starts automatically on every boot — preventing Metasploit from failing to connect after a reboot.

Step 4 — Verify

Run systemctl status postgresql to confirm the service is active (running) before launching Metasploit. Checking service status before running tools prevents frustrating false negatives caused by a stopped dependency service.

Step 5 — Enumerate

On a compromised target, run systemctl list-units –type=service –state=running to enumerate all active services — revealing databases, web servers, FTP daemons, and other processes that represent additional attack surface or lateral movement opportunities.

On a target system, systemctl list-units –type=service is one of the first commands a penetration tester runs during post-exploitation enumeration. Running services reveal the attack surface: an active MySQL service may have weak credentials; a running FTP daemon may allow anonymous login; an enabled cron service may run scripts with root privileges.

Pro tips: package managers and systemctl for security professionals

apt security tip: Always run an update before installing

Run apt update before every apt install to ensure you are installing the latest, patched version of a tool from the repository — not a cached, outdated version.

apt security tip: Use apt-cache for recon

On a compromised target, apt list –installed reveals every installed package — exposing the software stack, server roles, and potentially vulnerable versions without generating network traffic.

systemctl security tip: Disable unused services

Run systemctl disable on every service that is not required. Each running service is an attack surface. Hardened systems run only what they need — nothing more.

systemctl security tip: Check service file permissions

Service unit files in /etc/systemd/system/ that are writable by non-root users are a critical privilege escalation path — a compromised user can modify the service to execute arbitrary commands as root.

Scroll to Top