Linux Command Reference ยท Special Files and Directories
/etc/environment and /etc/profile.d
Reference for system-wide environment settings: /etc/environment syntax, /etc/profile.d scripts, login versus non-login shells and which file to choose.
Two places hold environment settings that apply to every user. /etc/environment is a plain list of NAME=value pairs read by PAM at login; it is not a script. /etc/profile.d/*.sh is a directory of small shell scripts that /etc/profile runs at the start of every login shell, so it can contain real shell code: conditions, export, PATH changes.
Pick by what you need: a fixed value for every kind of session (graphical, SSH, su) belongs in /etc/environment; anything that needs logic belongs in a script in profile.d. Neither affects processes that are already running, and neither is read by cron or by systemd services.
# /etc/environment EDITOR=vim # /etc/profile.d/myapp.sh export MYAPP_HOME=/opt/myapp
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
/etc/environment: one NAME=value per line. Values may be quoted. Comments start with #. There is no shell here, so PATH=$PATH:/opt/bin does not expand $PATH; write the full value. No export and no command substitution. The file is read by pam_env, only if the PAM stack of the login service includes it.
/etc/profile.d/NAME.sh: ordinary shell code. Only files ending in .sh are loaded by most systems (Debian's /etc/profile loops over *.sh; Red Hat-family systems also accept *.csh for csh). Files are loaded in alphabetical order, so numeric prefixes (10-, 50-) control the order. The scripts are read by sh-compatible shells, so avoid Bash-only syntax unless you guard it.
Usage notes
- Login vs non-login:
/etc/profileruns for login shells (SSH, console,su -). A new terminal window in a desktop session is often a non-login shell and reads~/.bashrcinstead;/etc/bash.bashrcis its system-wide counterpart on Debian. - Changes need a new login. Start a fresh session or run
. /etc/profileto test. - Services and cron do not see these files. For a systemd unit use
Environment=orEnvironmentFile=; cron has its own tiny environment andPATH. - Do not put secrets in either file: both are readable by all users.
- Avoid
PATHduplicates with a guard like the one above, because the script runs again in nested login shells. - No output: anything echoed from
profile.dappears in every login, and can breakscpandrsyncover SSH. - Per-user settings go in
~/.profile, see home directory dotfiles. - See what a process received with
envor/proc/PID/environ.