Understanding /etc/profile Configuration File in Linux

The /etc/profile file provides system-wide environment variables. This may be more effective for administrators to configure if there are settings that apply to all users.

During the initial login process for a user, the system reads the /etc/profile file first for Bash shell configurations, and then any user-specific Bash customizations are pulled from the .profile file located in the user’s home directory. The .profile file runs each time a new shell is started, whereas /etc/profile is only run at login. This approach enables administrators to define global shell settings, but still allow user-specific customizations.

Note: The global file is /etc/profile (without the “dot” as the first character of the file name), while the user-specific file is .profile, indicating that the file is hidden.

The profile file located in /etc is read automatically by everyone when they log in. This file will generally contain:

  • global or local environment variables
  • PATH information
  • terminal settings
  • security commands
  • message of the day or disclaimer information

An example of a .profile is as follows:

# cat /etc/profile
PATH=$PATH:$HOME/bin:/scripts
MAIL=/var/mail/$LOGNAME
EDITOR=emacs
export PATH MAIL EDITOR

The first line defines the paths of executable files; the second line defines the path for where incoming email messages are stored; and the third line defines the default text editor. The last line actually ensures these variables are implemented in the environment.

The /etc/profile.d/ Directory

The /etc/profile.d/ directory serves as a storage location for scripts administrators may use to set additional system-wide variables. It is recommended you set the environment variables via scripts contained in /etc/profile.d/ rather than editing the /etc/profile file directly.

Related Post