A system service started by systemd’s system manager does not automatically import variables from /etc/environment. That file is commonly read by PAM during some login flows, which can make a variable appear in a terminal while it remains absent from a system service. Set variables in the scope that starts the process: the service unit for a system service, or the user manager’s environment.d configuration for a user service.
Why a variable appears in your terminal but not in a service
/etc/environment is a simple file of KEY=VALUE assignments, not a universal environment file that every process reads. A common reason its values appear in a login session is PAM’s pam_env module. When that module is included in the relevant PAM stack and invoked through a suitable application flow, it reads /etc/environment by default.
As an Amazon Associate I earn from qualifying purchases.
The login path matters: according to the Linux-PAM pam_env(8) manual, the module only executes if the main application calls pam_setcred() or pam_open_session(); it does nothing when called by pam_authenticate(). PAM configuration differs by distribution and service, so seeing a variable in one login does not show that systemd imported it.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Which component supplies the environment?
| Process scope | Configuration mechanism | When it applies |
|---|---|---|
| Login session | /etc/environment read by PAM’s pam_env, if the module is configured and the login flow invokes it |
During the relevant PAM session or credential setup |
| System service | Unit-level Environment= or EnvironmentFile=; selected manager variables can be passed with PassEnvironment= |
When the system manager starts the service |
| User service | The user manager’s environment.d configuration or another explicit user-manager environment mechanism |
For services started by that user manager |
| System-wide locale | locale.conf |
For locale settings, not arbitrary service-specific variables |
These mechanisms have different scopes and lifecycles. A user manager’s configuration does not configure system services. Likewise, locale.conf is for system-wide locale settings, not a general-purpose replacement for service environment settings.
#1 Best Overall
Set a variable for one system service
For a single system unit, use a unit drop-in and a dedicated environment file. This keeps the setting attached to the service that needs it rather than relying on an unrelated login mechanism.
-
Create or edit the service’s drop-in with
sudo systemctl edit example.service. -
Add the following configuration:
[Service] EnvironmentFile=/etc/example-service/environment -
Create
/etc/example-service/environmentwith simple newline-separated assignments, such asMODE=production. Use the syntax supported by the installed systemd version; this file is not a shell script to source.Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Save the drop-in, then run
sudo systemctl daemon-reloadso the manager reads the changed unit configuration. -
Restart the service with
sudo systemctl restart example.service. A running process does not acquire changed environment variables merely because its unit or environment file was edited.
You can also put a non-sensitive value directly in a drop-in with Environment=NAME=value. The systemd.exec manual documents Environment=, EnvironmentFile=, and service execution behavior. An environment file is read shortly before the service process executes, from the service manager’s filesystem view.
Rank #3
Use the right mechanism for a user service
A service started by a systemd user manager belongs to a different scope from a system service. The systemd project’s environment.d documentation describes files that configure the environment exported by a user instance and passed to services that instance starts. Use the applicable ~/.config/environment.d/ location for a user-specific setting, or the relevant system-wide environment.d directory where appropriate.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallChanges to a user manager’s environment may require updating the manager environment or restarting services, depending on when the variable is consumed. Confirm the behavior for the installed systemd release and the service’s lifecycle; do not expect user-manager settings to reach a system service.
Keep service environments deliberate
systemd’s execution-environment documentation describes its general philosophy as exposing “a small curated list of environment variables to processes.” It discourages importing every variable from a graphical session or user shell. For service configuration, that means selecting the values the process actually needs instead of trying to copy an entire interactive environment.
Do not casually put passwords, tokens, or other secrets in ordinary environment assignments. The systemd documentation warns that unit environment variables may be exposed to unprivileged clients and recommends credential directives for sensitive data. Check the installed systemd.exec(5) manual for the credential options supported by that host.
Check what the service manager will pass
For a quick view of the environment provided by each manager, the systemd execution-environment documentation suggests these commands:
Free tools Windows power users keep installed
One-click scans. No signup required.
systemd-run -P env
systemd-run --user -P env
The first checks the system manager’s environment; the second checks the user manager’s. They do not by themselves prove the exact environment of an already-running unit. For a real service, inspect its unit and drop-ins, then verify the environment of the process itself or use a minimal diagnostic command appropriate to that service.
Best Value
What to check when the variable is still missing
-
Identify the manager. Determine whether the process is started by the system manager or a user manager before choosing a configuration path.
-
Confirm the unit configuration. Check the effective unit and its drop-ins for the intended
Environment=orEnvironmentFile=entry. -
Check the file and syntax. Confirm the environment file exists, is readable in the service manager’s filesystem view, and contains valid assignments for the installed systemd version.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Restart the process. A process already running will not have its environment changed by editing a file.
-
Check PAM separately. If the value exists only in a login session, inspect the PAM service stack and login path that loaded it rather than assuming the system service shares that session.
PAM stacks and systemd builds vary by distribution and release. The upstream systemd manuals are rolling documentation, so compare their guidance with the host’s installed systemd.exec(5), environment.d(5), and PAM service files before relying on version-specific behavior.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




