LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the effective SSH $PATH when executing a command (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-effective-ssh-%24path-when-executing-a-command-705676/)

nlainus 02-18-2009 01:39 PM

What is the effective SSH $PATH when executing a command
 
Hi all, I hope I'm in the right forum.

I have a cluster containing 32 compute nodes and 1 head node. I have a common user account which is being exported via the head node to all compute nodes - so all nodes can access the same files and "SHOULD" have the same environment as each other. I also have passwordless ssh and rsh setup between all nodes.

As you will see if you examine the commands below there is something strange happening when ssh'ing. Essentially your effective permissions change when running a command over SSH. I can't figure out where its getting this alternate path variable from. The .bash_profile is shared between all nodes so they should have the same path when entering as that user (fluent).

Any help on this would be greatly appreciated. I've exhausted all my local resources here at work and everyone is stumped.

_________________________________________________
[fluent@colfax60 ~]$ ssh amd-1 echo $PATH
/usr/ansys_inc/v120/fluent/bin:/opt/hpmpi/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/kerberos/sbin:/usr/kerberos/bin

[fluent@colfax60 ~]$ ssh amd-1 'echo $PATH'
/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin
[fluent@colfax60 ~]$

[fluent@colfax60 ~]$ ssh amd-1 which fluent
which: no fluent in (/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin)
[fluent@colfax60 ~]$

[fluent@colfax60 ~]$ ssh amd-1
Last login: Wed Feb 18 13:34:06 2009 from colfax60

[fluent@AMD-1 ~]$ which fluent
/usr/ansys_inc/v120/fluent/bin/fluent
[fluent@AMD-1 ~]$
_________________________________________________

bluethumb 02-18-2009 02:47 PM

Interactive vs. non-interactive
 
From the bash man page:

Quote:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following command were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the file name.
So when you ssh a command, it uses a different set of dot files than the ones you get in an interactive shell.

nlainus 02-18-2009 03:02 PM

I fixed this folks. Red Hat runs your profile vars like this - /etc/profile /etc/bashrc ~/.bashrc "OR" ~/.bash_profile
Something broke to where it wasn't running the ~/.bash_profile when ssh'ing under certain circumstances but when I added the desired path the ~/.bashrc for that user it all was peachy.

Thanks and I hope this helps someone else down the road.

nlainus 02-18-2009 03:05 PM

Sorry I didn't see your post in time before my own response to resolve this, but thanks for the info! That is much help.

nx5000 02-18-2009 03:09 PM

strange..
Ssh command uses path specified when building sshd
Path should not be set in bashrc.
If they are and exported:
Ssh in and type 'bash'
You might have everything doubled
If they are but not exported:
Create a file containing
echo $PATH
Execute it

nlainus 02-19-2009 11:17 AM

I always thought that running "ssh host command" would take on the permissions of whatever user you were executing the ssh command from. That's how its always worked for me. Then all of a sudden it wasn't working anymore.

nx5000 02-19-2009 11:23 AM

I read the manpage and it says by default, ssh command will take the PATH used while building sshd. Kinda strange. Probably security reasons.

For the rest, I checked a RH and I confirm that it's the default settings, if you put things in .bashrc, you can get them defined multiple times.
So it's cleaner in profile.

nlainus 02-19-2009 05:01 PM

Thanks for the info.


All times are GMT -5. The time now is 03:16 AM.