if you want to see the current target:

systemctl list-units --type=target #check available targets
systemctl get-default #check default target
systemctl list-dependencies #list the depnedices of current target
systemctl list-dependencies <target>#list the depnedices of specified target
systemctl set-default multi-user.target #change the default target
systemctl isolate rescue.target #change the target without rebooting
sysctemctl cat sshd.service # see which target the service is required (wanted by)

default target contains multi-user target. that means we are in graphical target

you can see to which target a specific services is needed

Setting the Default Systemd Target

Systemd targets are a way to group and manage system states in Linux systems that use the systemd init system. They are conceptually similar to runlevels in older init systems like SysVinit but provide more flexibility and finer-grained control.

Key Concepts of Systemd Targets

  1. Purpose of Targets: Targets represent different states or stages of the system, such as booting up, shutting down, or preparing a graphical desktop environment. They group together related services, mount points, and other units.

  2. Common Targets: Here are some commonly used systemd targets:

    • basic.target: A minimal system state with basic services started.
    • multi-user.target: A non-graphical, multi-user system state (similar to runlevel 3 in SysVinit).
    • graphical.target: A graphical desktop environment (similar to runlevel 5 in SysVinit).
    • rescue.target: A single-user mode for system repair (similar to runlevel 1).
    • emergency.target: A minimal environment for emergency system recovery.
    • default.target: The target that the system boots into by default (usually a symlink to graphical.target or multi-user.target).
  3. Target Files: Targets are defined as unit files in /usr/lib/systemd/system/ or /etc/systemd/system/. For example, multi-user.target corresponds to a file named multi-user.target.

  4. Dependencies: Targets define dependencies on other units (services, mounts, etc.). When a target is activated, all its dependencies are started.


Managing Targets

  1. Checking the Current Target: Use the following command to see the current active target:

    systemctl get-default
  2. Changing the Default Target: To change the target the system boots into:

    sudo systemctl set-default <target>.target

    For example:

    sudo systemctl set-default graphical.target
  3. Switching to a Different Target: You can switch to another target without rebooting using:

    sudo systemctl isolate <target>.target

    For example:

    sudo systemctl isolate multi-user.target
  4. Listing Available Targets: To see a list of available targets:

    systemctl list-units --type=target

How Targets Work

Targets primarily manage which units (services, mounts, etc.) are active. When you activate a target:

  • Systemd activates all units specified in the [Unit] section of the target’s configuration file.
  • It ensures all dependencies for those units are met.

Example Use Case

Suppose you want to boot your system into a minimal environment for debugging purposes. You can:

  1. Boot into rescue.target:

    sudo systemctl isolate rescue.target
  2. Restore the system to its regular graphical environment:

    sudo systemctl isolate graphical.target