Understanding Linux Login: The Order of Profile and Bash Files Explained
This article explains the exact sequence of files executed during Linux login, including /etc/profile, user-specific profiles, .bashrc, /etc/bashrc, and .bash_logout, and clarifies the roles of /etc/profile versus /etc/environment in setting system and user environments.
When logging into Linux, the system first executes /etc/profile, then one of the user’s startup files: ~/.bash_profile, ~/.bash_login, or ~/.profile. The typical order is ~/.bash_profile → ~/.bash_login → ~/.profile.
If ~/.bash_profile exists, it usually sources ~/.bashrc with the following code:
if [ -f ~/.bashrc ] ; then
. ./bashrc
fiInside ~/.bashrc, the system‑wide /etc/bashrc is often sourced:
if [ -f /etc/bashrc ] ; then
. /etc/bashrc
fiThus the full execution chain is:
/etc/profile → ( ~/.bash_profile | ~/.bash_login | ~/.profile ) → ~/.bashrc → /etc/bashrc → ~/.bash_logoutFile responsibilities:
/etc/profile : Sets environment for all users at first login and reads scripts from /etc/profile.d.
/etc/bashrc : Executed for every Bash shell instance; runs each time a new terminal opens.
~/.bash_profile : User‑specific login shell configuration; runs once per login and typically calls ~/.bashrc.
~/.bashrc : Contains settings for interactive non‑login shells; read on each new shell.
~/.bash_logout : Executed when exiting a Bash session.
The system also reads /etc/environment, which defines system‑wide environment variables independent of any user login. While /etc/profile configures user‑specific settings, /etc/environment applies globally.
Changing LANG in /etc/profile makes login prompts appear in English; moving it to /etc/environment makes the change affect all users regardless of login method.
In summary, for a user’s shell initialization the order is /etc/profile then /etc/environment, whereas for the whole system /etc/environment is considered first.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
