1

My problem is

$ ssh localhost fswatch          
bash: fswatch: command not found

when without SSH command (i.e. fswatch) works fine.

I found that PATH in SSH session is default Mac's

$ ssh localhost echo \$PATH        
/usr/bin:/bin:/usr/sbin:/sbin

since without SSH

$ echo $PATH
/Users/kyb/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I really do not remember how have I set up the PATH, but sure ~/.bashrc and ~/.bash_profile do not edit PATH variable. There is a config file /etc/paths:

$ cat /etc/paths         
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Homebrew, npm, pip usually install programs to /usr/local/bin, so all installed programs are there and I can't access them via ssh localhost command on my MacOS. There is no problem with Linux.

So my question is how to configure OpenSSH to use PATHs from /etc/paths and /etc/paths.d?

I also tried to hack:

$ ssh localhost sh -lc 'echo empty;echo $PATH'

/usr/bin:/bin:/usr/sbin:/sbin
$ ssh localhost bash -lc 'echo empty;echo $PATH'

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

first line is always empty, don't you know why?

And my final workaround

$ ssh localhost bash -lc ':; 
    export PATH="$( cat /etc/paths /etc/paths.d/* | tr \\\\n : )"; 
    echo $PATH; 
    fswatch --version'
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/VMware Fusion.app/Contents/Public
fswatch 1.14.0
Copyright (C) 2013-2018 Enrico M. Crisostomo <enrico.m.crisostomo@gmail.com>.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Enrico M. Crisostomo.

Here first :; is important because first command is somehow dropped from execution

System: MacOS Mojave 10.14.5
ssh -V: OpenSSH_7.9p1, LibreSSL 2.7.3
bash --version GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.