3

Using ssh between 2 Pi's, I need to alter the path that is seen within ssh. If I read the path locally I see

pi@pi-test:~ $ echo $PATH
/home/pi/.guix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/snap/bin
pi@pi-test:~ $ 

however if I look via ssh from another Pi I see

pi@pi4b:~ $ ssh pi@pi-test-wifi 'echo $PATH'
pi@pi-test-wifi's password: 
/usr/local/bin:/usr/bin:/bin:/usr/games
pi@pi4b:~ $ 

How can I see the path which is seen inside ssh? I have done some research but the solutions I have found are old and the option files referred to don't seem to exist anymore. Thanks Mick

0
3

I think your question is answered in this Q&A on Unix & Linux SE. Briefly:

  1. on the "server" host (pi-test-wifi I believe) - edit the file /etc/ssh/sshd_config as follows:

    FROM: # PermitUserEnvironment no

    TO: PermitUserEnvironment yes

  2. on the "server" host, create or modify the file ~/.ssh/environment, and add the following line:

    PATH=/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

    Alternatively, set the PATH to whatever you wish, however you wish - as long as you do it in this file.

  3. Reboot, or sudo service ssh restart

This worked for me:

pi@raspberrypi3b:~ $ ssh pi@raspberrypi4b.local 'echo $PATH'
pi@raspberrypi4b.local's password:
/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pi@raspberrypi3b:~ $
2
  • Brilliant!! Thank you, I have been trying to fix this for several days no. Dec 16 '20 at 11:29
  • @MickSulley: Glad it helped. It took me a few minutes to grasp what you were trying to do 'cause my typical MO is using SSH to access an interactive shell. Using it the way you've described will be very useful at times - so I learned something as well!
    – Seamus
    Dec 17 '20 at 2:03
0

The PATH will be the same as the user.

ssh pi@pi-test-wifi 'echo $PATH' doesn't do what you think.

If you ssh into the Pi THEN list the PATH you will get the true value.

NOTE Your question is confused pi-test-wifi is NOT pi-test

1
  • Sorry for the confusion, my device naming is a bit unorthodox. I need to run unison across machines and it needs to see the correct path in the remote machine, so I need to change the path which is seen in the example, and I cannot figure out how to do it. Dec 16 '20 at 9:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.