1

How can I make ssh admin@nas command work if command is in /opt/bin?

On my QNAP NAS File /root/.ssh/rc:

echo "old path is $PATH"
export PATH=/opt/bin:/opt/sbin:$PATH
echo "new path is $PATH"

on my machine:

~$ ssh admin@nas 'echo $PATH'

returns

old path is /usr/bin:/bin:/usr/sbin:/sbin
new path is /opt/bin:/opt/sbin:/usr/bin:/bin:/usr/sbin:/sbin
/usr/bin:/bin:/usr/sbin:/sbin

so the path variable is not preserved. How can I achieve that?

Edit: As I mentioned in my comment below the command I'm trying to use is git or, more specific git-upload-pack and git-receive-pack and probably some others. I want to use them in different locations and occasions and don't want to bother setting up a git config on every machine I use it on or teach my IDE how to communicate with my NAS but rather have my NAS conforming standards. So i figured that all I need is to set the right $PATH

Edit II: what i did try so far was also inserting the export PATH=... as well as adding another echo (to verify they're run) to ~/.bash_profile, to /etc/profile and to ~/.bashrc. Apparently none of them are even executed when I run a non-interactive command like above. If I do ssh admin@nas all of them are executed, but that doesn't help

6
  • stick it in ~/.bash_profile
    – shorif2000
    Apr 19, 2013 at 14:35
  • i tried that along with adding another echo (to verify they're run) to ~/.bash_profile, to /etc/profile and to ~/.bashrc. Apparently none of them are even executed when I run a non-interactive command like above. If I do ssh admin@nas all of them are executed, but that doesn't help Apr 19, 2013 at 14:43
  • How about ~/.bashrc? Apr 19, 2013 at 20:11
  • As described in my previous comment, I tried that Apr 20, 2013 at 12:33
  • log into root using su -
    – shorif2000
    Apr 22, 2013 at 9:37

2 Answers 2

1

If you are logged in as admin, ~/.bashrc is not used but ~/.profile is. So you can add this to .profile:

export PATH=\
/bin:\
/sbin:\
/opt/bin:\  #<--- HERE IT IS NOW
/usr/bin:\
/usr/sbin:\
/usr/bin/X11:\
/usr/local/bin

And PATH will be loaded like this when you login as admin. What I did on my nas is I added this to .bashrc, and changed .profile to have only 1 line:

source ~/.bashrc

So when you login as admin, you still get SH configured with .bashrc.

EDIT: I now understand what you want to do...

Just create symbolic links to those two binaries inside /usr/bin. For example:

cd /usr/bin && ln -s /opt/bin/git-upload-pack 
0

You can enter real address of command instead of command in ssh admin@nas command. Like below:

ssh admin@nas /opt/bin/command-name

1
  • thanks for the reply, this does work but the command I'm trying to use is git or, more specific git-upload-pack and git-receive-pack and probably some others. I want to use them in different locations and occasions and don't want to bother setting up a git config on every machine I use it on or teach my IDE how to communicate with my NAS but rather have my NAS conforming standards. So i figured that all I need is to set the right $PATH Apr 19, 2013 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .