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
  • 1
    `I already tried different approaches` -- This vague statement is not helpful. Please [edit] the question and tell us what you tried exactly. – Kamil Maciorowski Jan 31 '19 at 07: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
  • 4,554
  • 3
  • 20
  • 38
  • Unfortunately I did not yet find the location where I have to place this export statement. Can you give me further advise? – Pete Jan 31 '19 at 18:05
  • That's a command that you run on any shell. You need to add it to your ~/.profile or ~/.bashrc file if you want it to load automatically. – HackSlash Jan 31 '19 at 18:13
  • I have it already in /etc/profile, /etc/environment, ~/.profile, ~/.bashrc without success. "ssh git@srv 'echo $PATH'" still returns "/usr/bin:/bin" – Pete Jan 31 '19 at 19:51
  • Sorry, I didn't realize the problem was that you are pushing commands via SSH. See my updated answer. – HackSlash Jan 31 '19 at 20:39
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"'
crimson-egret
  • 3,276
  • 17
  • 20