[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: SOLVED Re: Cannot rum multiple command on remote machine via SSH



On Mon, Feb 06, 2023 at 07:54:20PM +0000, Ottavio Caruso wrote:
> Am 06/02/2023 um 19:05 schrieb Greg Wooledge:
> > ssh LAP2 'type hibernate.sh; echo "$PATH"'
> 
> _Touché !_ You nailed it:
> 
> 
> $ ssh LAP2 'type hibernate.sh; echo "$PATH"'
> bash: line 1: type: hibernate.sh: not found
> /usr/local/bin:/usr/bin:/bin:/usr/games
> 
> For some reason, I though ssh would inherit the $PATH from .profile, which
> sources .bashrc, but of course this is not an interactive shell.

It gets complicated.  This is why I was asking for all the information
I was asking for.

On most Linux systems, including Debian, bash is built with a compile-time
option that makes it try to determine whether it's a child of sshd.  If
it believes itself to be that, it will source ~/.bashrc even though it's
not an interactive shell.

A completely vanilla upstream bash, straight from gnu.org, doesn't do
that.  Here's the option in config-top.h:

/* Define this if you want bash to try to check whether it's being run by
   sshd and source the .bashrc if so (like the rshd behavior).  This checks
   for the presence of SSH_CLIENT or SSH2_CLIENT in the initial environment,
   which can be fooled under certain not-uncommon circumstances. */
/* #define SSH_SOURCE_BASHRC */

But Debian turns that feature on, so you get:

unicorn:~$ echo 'echo this is .bashrc' >> ~/.bashrc
unicorn:~$ ssh localhost true
greg@localhost's password: 
this is .bashrc
unicorn:~$ 

If you really are defining your PATH in ~/.bashrc, with LAP2 being a
Debian system, and your account's shell being /bin/bash, it's quite
surprising that what you're doing isn't working the way you expected.

Of course, if you're actually defining PATH in ~/.profile (which is far
more sensible in most cases), then it's not a surprise.


Reply to: