LinuxCommandLibrary

systemctl-unset-environment

Remove systemd environment variables

TLDR

Unset a single environment variable

$ systemctl unset-environment [var]
copy

Unset multiple environment variables at once
$ systemctl unset-environment [var1 var2 ...]
copy

Unset an environment variable in the user service manager
$ systemctl unset-environment [var] --user
copy

SYNOPSIS

systemctl unset-environment [VARIABLE...]

PARAMETERS

VARIABLE
    The name of an environment variable to remove from the systemd manager's global environment. Multiple variable names can be specified, separated by spaces. If no variables are specified, the command does nothing.

DESCRIPTION

systemctl unset-environment is a powerful command used to remove one or more global environment variables that have been previously set for the systemd manager itself and consequently for all its child processes, which includes services, sockets, mounts, and other units it manages. When a new systemd unit starts, it inherits the environment variables currently defined for the systemd manager. Unsetting these variables can be crucial for various purposes such as security hardening, resource cleanup, or to prevent the unintended propagation of specific environment settings to newly launched services.

It's important to note that the changes made by this command are transient; they only affect processes started after the command is executed and do not persist across system reboots. Furthermore, already running services will not be affected and will continue to operate with their existing environment. To achieve persistent environment variable changes across reboots, users should instead modify systemd configuration files like /etc/systemd/system.conf.d/*.conf or the system-wide /etc/environment file.

CAVEATS

Changes made by systemctl unset-environment are transient; they do not persist across system reboots and must be re-applied or configured through persistent files for permanent effect.
This command only affects new processes started by systemd after its execution. Already running services or processes will retain their existing environment variables.
Execution typically requires root privileges (or appropriate D-Bus permissions) to modify the systemd manager's environment.
Unsetting critical environment variables could potentially disrupt system services or applications if not done carefully.

PERSISTENCE

To make environment variable changes permanent across reboots, they should not be managed solely with systemctl unset-environment. Instead, define environment variables in systemd configuration files such as /etc/systemd/system.conf.d/*.conf (e.g., using `DefaultEnvironment=`), the system-wide /etc/environment file, or through custom environment generator scripts.

SCOPE OF EFFECT

The global environment variables managed by systemctl set-environment and unset-environment are inherited by *all* services and units started by the systemd user or system manager. For managing environment variables specific to a single service, it is generally recommended to use the `Environment=` or `EnvironmentFile=` directives within that service's unit file (e.g., /etc/systemd/system/myservice.service) for better encapsulation and control.

HISTORY

The set-environment and unset-environment subcommands were introduced with systemd version 232 (released around late 2016 / early 2017). These commands provided a convenient, runtime mechanism for administrators to manage global environment variables for the systemd manager, complementing existing methods of environment configuration via unit files and system-wide configuration files.

SEE ALSO

systemctl(1), systemctl set-environment(1), systemd.exec(5), systemd.environment-generator(7), environment.d(5)

Copied to clipboard