DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

/etc/environment Isn’t Read Automatically by systemd—Here’s Why

A login session may get variables from /etc/environment through PAM, but a systemd system service does not import that file automatically. Set service variables in the correct manager scope.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

  1. Create or edit the service’s drop-in with sudo systemctl edit example.service.

  2. Add the following configuration:

    [Service]
    EnvironmentFile=/etc/example-service/environment
  3. Create /etc/example-service/environment with simple newline-separated assignments, such as MODE=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.
  4. Save the drop-in, then run sudo systemctl daemon-reload so the manager reads the changed unit configuration.

  5. 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changes 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

What to check when the variable is still missing

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.