I have a CentOS VM to which I log in using SSH. I appended the following line to .bashrc
echo "from ~/.bashrc: (pid $$)"
and the following line to .bash_profile
echo "from ~/.bash_profile"
When I log into the VM and run ps
I get the following output
user@laptop:~ $ ssh vmcentos
Last login: Sun May 17 04:48:24 2020 from 192.168.122.1
from ~/.bashrc: (pid 1821)
from ~/.bash_profile
[admin@localhost ~]$ ps -H -o pid,command
PID COMMAND
1821 -bash
1844 ps -H -o pid,command
[admin@localhost ~]$
This output is what I expect since the shell I log into is an interactive login shell and thus the .bash_profile
file is sourced which in turn sources the .bashrc
file.
Now I log out from the VM and execute the following command
user@laptop:~ $ ssh vmcentos 'sleep 60; echo $-'
from ~/.bashrc: (pid 1901)
hBc
user@laptop:~ $
then I log into another ssh
session on the VM and inspect the process table
[admin@localhost ~]$ ps -eH -o pid,command
PID COMMAND
(... more output here...)
1900 sshd: admin@notty
1901 bash -c sleep 60; echo $-
1914 sleep 60
(... more output here...)
As far as I understand the shell that ssh
executes (process 1901) is non-interactive (because of the -c
option and also because the $-
variable contains no i
character) and non-login (because ARGV0
is not -bash
and no --login
option is provided). Thus neither .bashrc
nor .bash_profile
should be sourced. Yet the output of the command clearly shows that .bashrc
was sourced. Why?
I used a standard CentOS installation with the standard openssh
configuration.
scp
and anything else that might try to do something automatically and interpret the output.