1

I installed debian using debootstrap (debootstrap --arch=amd64 stretch /target http://httpredir.debian.org/debian). When I check my PATH variable i get:

ssh git@srv 'echo $PATH'
/usr/bin:/bin

How can I expand it and include e.g. /usr/local/bin?

/etc/passwd:

git:x:108:112:git version control,,,:/home/git:/bin/sh

I already tried the following approaches, but without success because these files are only read for interactive shells. Thanks for advices.

echo 'export PATH="/usr/a1:$PATH"' >> /etc/profile

echo 'PATH="/usr/a2:$PATH"' >> /etc/environment

echo 'export PATH="/usr/a3:$PATH"' >> /home/git/.profile
chown git:git /home/git/.profile

echo 'export PATH="/usr/a4:$PATH"' >> /home/git/.bashrc
chown git:git /home/git/.bashrc

echo 'PATH="/usr/a5:$PATH"' >> /home/git/.ssh/rc
chown git:git /home/git/.ssh/rc

echo 'export PATH="/usr/a6:$PATH"' >> /home/git/.ssh/environment
chown git:git /home/git/.ssh/environment
Pete
  • 11

2 Answers2

0

SSH commands like this are not affected by login or interactive environment variables.

This question is similar to the one asked here: https://unix.stackexchange.com/questions/332532/how-to-set-path-when-running-a-ssh-command

Try like this:

echo "export PATH=$PATH:/usr/local/bin" >> ~/.ssh/environment

HackSlash
  • 5,015
0

You can execute commands in a login shell on the remote host, which will process your shell config files (e.g. ~/.profile, etc):

ssh user@host 'exec $SHELL -l -c "echo $PATH; commmand; another-command"'

Depending on what you are trying to do, might need to tell ssh to create a pseudo-tty:

ssh user@host -t 'exec $SHELL -l -c "command-that-needs-tty"'