Why is SSH not invoking .bash_profile?

My understanding had been that .bash_profile would always be invoked via an SSH login.

However I am not seeing the various settings enabled unless I do the following:

ssh $host "source ~/.bash_profile ; echo $PATH "

.:/mnt/spark-1.4.1/bin:/mnt/spark-1.4.1/sbin:/mnt/scala-2.11.2/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

When I simply do:

ssh $host "echo $PATH "

The PATH info is just the default

 /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

The user is root and the default shell is bash.

$ ll /bin/sh
lrwxrwxrwx 1 root root 4 Aug  6 19:54 /bin/sh -> bash

Update root’s shell is bash

grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash

Answer

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|Interactive|Script|
|                |login      |non-login  |      |
+----------------+-----------+-----------+------+
|/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.

Attribution
Source : Link , Question Author : WestCoastProjects , Answer Author : Giacomo1968

Leave a Comment