Why is SSH not invoking .bash_profile?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Why Is Ssh Not Invoking .Bash_profile?
00:33 Answer 1 Score 7
01:07 Answer 2 Score 1
01:25 Accepted Answer Score 13
01:38 Answer 4 Score 2
02:17 Thank you
--
Full question
https://superuser.com/questions/952084/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #ssh
#avk47
ACCEPTED ANSWER
Score 13
SSH with a command will NOT start a login shell. Thus bash_profile is not sourced.
See details here
ANSWER 2
Score 7
Do you have a .bashrc
file set? It could be damaged or corrupted or has something that causes the processing of .bashrc
to choke and fail. And as a result, the doesn’t get to the point where it can cleanly digest/process .bash_profile
.
As shown on this site, .bashrc
loads before .bash_profile
:
Interactive login | Interactive non-login | Script | |
---|---|---|---|
/etc/profile |
A | ||
/etc/bash.bashrc |
A | ||
~/.bashrc |
B | ||
~/.bash_profile |
B1 | ||
~/.bash_login |
B2 | ||
~/.profile |
B3 | ||
BASH_ENV |
A | ||
~/.bash_logout |
C |
I would recommend checking that .bashrc
and maybe even temporarily renaming it something like .bashrc_off
to disable it to test the theory before debugging any further.
ANSWER 3
Score 2
add -l
may be an easy workaround, -l
option makes bash act as a login shell, a login shell will execute .bash_profile.
ssh $host bash -l -c single_word_command
or
ssh $host bash -l -c '"commands with space"'
because $
sign needs escape, to echo $PATH some additional work is needed, something like
ssh $host bash -l -c "'echo \$PATH'"
the \
before $
prevent "local" shell to replace $PATH to real value, the '
in "
is needed because outer "
is removed after sending to "remote"
by the way
ssh -v
and bash -v
is very helpful for debugging escape things like this
ANSWER 4
Score 1
What was that last bit about /bin/sh
? If root's default shell is set to /bin/sh
, then bash
will be invoked in POSIX Bourne shell compatibility mode, where bash
-specific startup scripts will not be run.