Master Linux Runlevels and Systemd Targets: How to View, Change, and Secure Them
This guide explains the purpose of Linux runlevels, maps them to systemd targets, shows how to check the current runlevel, change it temporarily or permanently, list services per level, create custom levels, and improve system security through fine‑grained service control.
Why Linux Runlevels Matter
Runlevels are distinct operating modes that determine which processes and services start or stop, allowing administrators to control system behavior for different use cases such as command‑line only or full graphical environments.
Standard Runlevels and Their Functions
0 : Power‑off the system.
1 : Single‑user (maintenance) mode, sometimes labeled S.
2 : Multi‑user without networking.
3 : Multi‑user with networking (text console).
4 : Reserved for custom configurations.
5 : Multi‑user with graphical display manager.
6 : Reboot.
Checking the Current Runlevel
Run runlevel in a terminal. The output shows two numbers: the previous runlevel and the current one. For example, N 5 means the system is now in runlevel 5.
Temporarily Changing the Runlevel
Use telinit as root. To switch to runlevel 3 on CentOS: $ telinit 3 After the change, runlevel will display the new current level and the previous one.
Systemd Targets vs. Traditional Runlevels
Modern distributions replace SysV init with systemd. Runlevels are now called "targets" and map as follows:
Runlevel 0 = poweroff.target Runlevel 1 = rescue.target Runlevel 2 = multi-user.target Runlevel 3 = multi-user.target Runlevel 4 = multi-user.target Runlevel 5 = graphical.target Runlevel 6 =
reboot.targetChanging the Default Target at Boot
To set runlevel 3 as the default, create a symbolic link pointing to the desired target:
$ ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.targetVerify the change with: $ systemctl get-default The command should return multi-user.target, which corresponds to runlevel 3.
Listing Services Enabled for a Specific Target
For the graphical target (runlevel 5), run: $ systemctl list-dependencies graphical.target Replace graphical.target with any other target name to see its services.
Finding Which Runlevel a Service Runs In
Query a service’s WantedBy property. Example for SSH: $ systemctl show -p WantedBy sshd.service The output shows multi-user.target, meaning SSH starts in runlevels 2, 3, and 4.
Enabling a Service for All Runlevels
To make SSH start in the graphical target as well, enable it:
$ systemctl enable sshd.serviceSecurity Benefits of Precise Runlevel Control
Limiting the system to only the services required for a given runlevel reduces attack surface and conserves resources. Administrators can avoid unintentionally exposing services by switching to a lower runlevel when a GUI is unnecessary.
Creating a Custom Runlevel (Target)
Copy an existing target, e.g., graphical.target, to a new file:
$ cp /usr/lib/systemd/system/graphical.target /usr/lib/systemd/system/mynew.targetCreate a directory for the new target’s wants: $ mkdir /etc/systemd/system/mynew.target.wants Then symlink or enable additional services in that directory as needed.
Choosing the Right Runlevel for Your Use Case
Runlevel 3 is ideal for servers or users who only need a command‑line interface. Runlevel 5 provides a full desktop environment. Runlevel 1 is suited for maintenance tasks on production servers. Runlevel 4 is rarely used and typically reserved for custom configurations.
Runlevels 0 and 6 are used only to power off or reboot the system, respectively, and are not intended for normal operation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
