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
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: 
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


2 Answers 2


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:


    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 [email protected] 'echo $PATH'
[email protected]'s password:
pi@raspberrypi3b:~ $
  • Brilliant!! Thank you, I have been trying to fix this for several days no. Dec 16, 2020 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, 2020 at 2:03

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

  • 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, 2020 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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