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

~/.bash_login is a hidden, per-user Bash script for login-shell setup. Bash checks login files in this order: /etc/profile, then the first readable personal file among ~/.bash_profile, ~/.bash_login, and ~/.profile. It stops after that first personal file; it does not read all three. Many terminal windows start non-login shells and read ~/.bashrc instead, so editing .bash_login may appear to do nothing.

What .bash_login is

The file normally lives at $HOME/.bash_login. The leading dot hides it from ordinary directory listings, but it is an ordinary shell script: Bash reads and executes its commands in the current shell process. Variable assignments, exported environment variables, functions, and other shell state can therefore affect the session that follows.

ls -la "$HOME/.bash_login"
nano "$HOME/.bash_login"
# or
vim "$HOME/.bash_login"

Bash documents this startup behavior in its startup-file rules.

When Bash reads it

A login shell is Bash invoked with --login or -l, or a process whose zeroth argument begins with a hyphen. You can create one for testing:

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

Check the current shell’s state:

case "$-" in
  *i*) echo "interactive" ;;
  *)   echo "non-interactive" ;;
esac

shopt -q login_shell && echo "login shell" || echo "not a login shell"

The -l, --login, --noprofile, and --norc options are described in Bash’s invocation documentation.

Bash’s startup-file order

For an interactive Bash login shell, the sequence is:

  1. /etc/profile, if present
  2. ~/.bash_profile, if it exists and is readable
  3. otherwise ~/.bash_login, if it exists and is readable
  4. otherwise ~/.profile, if it exists and is readable

The three personal files are alternatives. If .bash_profile exists, Bash skips .bash_login and .profile. If all three exist, only .bash_profile is selected.

A normal interactive non-login Bash shell reads ~/.bashrc. A non-interactive Bash script normally reads the file named by $BASH_ENV, when that variable is set. When Bash is invoked as sh, its startup rules change: login mode uses /etc/profile and ~/.profile, not Bash-specific .bash_profile or .bash_login. See the GNU Bash manual for these cases.

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

Comparing the personal startup files

File Purpose Login-file priority
~/.bash_profile Bash-specific personal login initialization 1
~/.bash_login Alternative Bash login initialization 2
~/.profile Traditional, shell-agnostic login initialization 3
~/.bashrc Interactive, non-login Bash configuration Not in the login fallback chain

Choose one primary login file instead of maintaining conflicting copies. Use .bash_profile for Bash-specific setup, .profile when several Bourne-compatible shells or desktop conventions must share the configuration, and .bash_login when that is the account’s deliberate Bash login file and no .bash_profile exists. There is no general technical advantage to .bash_login over .bash_profile.

What belongs in .bash_login

Login files are appropriate for environment that should be established when a login session starts:

# ~/.bash_login
export EDITOR=vim
export PAGER=less
export LANG=en_US.UTF-8

case ":$PATH:" in
  *":$HOME/bin:"*) ;;
  *) PATH="$HOME/bin:$PATH" ;;
esac
export PATH

Aliases, functions, prompt customization, and interactive shell options usually belong in ~/.bashrc:

alias ll='ls -alF'

mkcd() {
  mkdir -p -- "$1" && cd -- "$1"
}

If login sessions should also receive interactive settings, source .bashrc explicitly from the selected login file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# ~/.bash_profile
if [ -r "$HOME/.bashrc" ]; then
  . "$HOME/.bashrc"
fi

Use "$HOME" in tests and paths for clarity. Keep commands safe for every invocation; a login shell may be non-interactive, as with bash -lc.

Why changes to .bash_login seem ineffective

.bash_profile is taking precedence

Find which candidates exist and are readable:

for f in "$HOME/.bash_profile" "$HOME/.bash_login" "$HOME/.profile"; do
  if [ -r "$f" ]; then
    printf 'First readable login file: %sn' "$f"
    break
  fi
done

If .bash_profile is the selected file, either put the login configuration there or source .bash_login deliberately. Edit manually rather than repeatedly appending lines, which can create duplicate sourcing.

The current shell is non-login

Many graphical terminals start an interactive, non-login Bash and therefore read .bashrc. Confirm with shopt -q login_shell, then test with bash --login. Terminal-emulator settings differ by product and desktop environment, so there is no universal menu path.

A different shell is running

printf 'SHELL=%sn' "$SHELL"
ps -p "$$" -o args=

$SHELL usually identifies the account’s configured login shell, not necessarily the process currently running. The ps output is a better check of the active command.

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

The file is unreadable or contains a syntax error

test -r "$HOME/.bash_login" && echo readable || echo not-readable
bash -n "$HOME/.bash_login"

bash -n parses without executing the file. If a selected startup file exists but cannot be read, Bash reports an error.

The command has no visible output

Environment changes do not print anything by default. Verify their effects directly:

printf 'EDITOR=%sn' "$EDITOR"
printf 'PATH=%sn' "$PATH"
type ll 2>/dev/null || true

Testing and tracing safely

  1. Back up the file: cp -p "$HOME/.bash_login" "$HOME/.bash_login.bak.$(date +%Y%m%d-%H%M%S)" 2>/dev/null || true.
  2. Run a fresh login shell: bash --login.
  3. Validate syntax first with bash -n "$HOME/.bash_login".
  4. For a temporary visible marker, print a message to standard error and remove it after testing.

Bash tracing can show executed startup commands:

BASH_XTRACEFD=7 bash --login 7>bash-login.trace

Do not share a trace containing secrets: tracing can expose tokens, passwords, paths, and command arguments. On Linux, advanced troubleshooting can inspect file opens:

strace -e openat bash --login -c 'exit' 2>&1 | grep -E 'profile|bash_profile|bash_login|.profile'

strace is platform-dependent and is best reserved for cases where shell-level checks are inconclusive.

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

Reloading the file and avoiding duplicate PATH entries

Apply changes to the current shell with either command:

. "$HOME/.bash_login"
# or
source "$HOME/.bash_login"

Manual sourcing is not the same as starting a new login session. It can rerun commands, start programs, or duplicate environment entries. Make path changes idempotent:

for dir in "$HOME/bin" "$HOME/.local/bin"; do
  [ -d "$dir" ] || continue
  case ":$PATH:" in
    *":$dir:"*) ;;
    *) PATH="$dir:$PATH" ;;
  esac
done
export PATH

System files such as /etc/profile.d, /etc/bashrc, or /etc/bash.bashrc may also modify the environment, but those names are distribution conventions rather than universal Bash rules. Linux From Scratch documents common layouts and their differences at its Bash startup-file guidance.

Recovering from a broken startup file

Start a clean Bash without profile or interactive initialization:

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

Then inspect, rename, or restore the file that Bash actually selects:

mv "$HOME/.bash_login" "$HOME/.bash_login.disabled"
bash -n "$HOME/.bash_login.disabled"
cp -p "$HOME/.bash_login.backup" "$HOME/.bash_login"

Do not put commands that block, prompt for input, launch graphical programs, or fail on every invocation into a login file unless that behavior is intentional.

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

SSH and remote commands

An interactive ssh host session commonly receives a login shell, subject to the server and account configuration. An invocation such as ssh host 'some-command' is a remote non-interactive command and does not necessarily read the same files. Bash also has special behavior in some remote-shell-daemon contexts, so it should not be generalized to every SSH setup.

For automation, invoke the required shell mode explicitly:

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.
ssh host 'bash -lc '''printf "%sn" "$PATH"; command -v tool''''

For complex work, use a remote script rather than relying on an interactive user profile.

Security and portability

  • Startup files execute automatically; treat them as executable code and do not paste commands from untrusted sources blindly.
  • Keep passwords, API keys, and tokens out of profile files where possible; use an appropriate secret-management mechanism.
  • Quote variable expansions and avoid group- or world-writable directories in PATH.
  • Never add the current directory . to PATH; an unintended executable in the working directory could run before a trusted command. See the warning in Linux From Scratch.
  • Check ownership and permissions, for example ls -l "$HOME/.bash_login" and, when appropriate, chmod 600 "$HOME/.bash_login".
  • Use Bash syntax only in Bash-specific files. Shared .profile configuration should remain compatible with the shells that must read it.
  • Configure daemons through their service manager rather than depending on a user’s interactive startup files.

Quick decision guide

Need Recommended location
Environment variables for login sessions Selected login file: .bash_profile, .bash_login, or .profile
Aliases, functions, prompt, interactive options ~/.bashrc
Settings shared with other Bourne-style shells ~/.profile
System-wide login setup Distribution-supported /etc/profile or /etc/profile.d/*.sh
Service or daemon environment Service-manager configuration

The current GNU Bash Reference Manual is identified as Bash 5.3 and was updated May 18, 2025, but installed Bash versions vary by distribution; the login-file rules above are stable across modern Bash releases. Reference: GNU Bash Reference Manual.

Frequently Asked Questions

Does .bash_login run for every terminal?

No. It runs only when Bash starts as a login shell and only when .bash_profile is absent or unreadable. Many terminals start non-login shells that read .bashrc.

What happens if all three login files exist?

Bash reads only ~/.bash_profile, the first readable personal file in its order.

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

Does .bash_login affect shell scripts?

Normally no. Non-interactive Bash uses $BASH_ENV; a script reads login files only if Bash is explicitly invoked with login mode.

Where should aliases go?

Put interactive aliases in ~/.bashrc, then source that file from the selected login file when login sessions also need them.

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.