Contents

Load ~/.bashrc on SSH

On SSH login, ~/.bashrc was not load

Why?

  • A login shell first reads /etc/profile and then ~/.bash_profile.
  • A non-login shell reads from /etc/bash.bashrc and then ~/.bashrc.

An ssh command which does have a command, like ssh user@host, It will start a login shell, a login shell reads ~/.bash_profile.

An ssh command which does have a command, like ssh user@host :(: is command that does nothing), It will not start a login shell, therefore ~/.bashrc is what will be read.

Ref. Stackexchange - Why does remote Bash source .bash_profile instead of .bashrc

In my environment, there are no description in ~/.bash_profile to load ~/.bashrc.


files

man bash has following description by the way.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
FILES
       /bin/bash
              The bash executable
       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bashrc
              The systemwide per-interactive-shell startup file
       /etc/bash.bash.logout
              The systemwide login shell cleanup file, executed when a login shell exits
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file
       ~/.bash_logout
              The individual login shell cleanup file, executed when a login shell exits
       ~/.inputrc
              Individual readline initialization file

Fix

Add below in ~/.bash_profile.

1
2
3
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Then bashrc is loaded on SSH login to ubuntu.


References