Forum Discussion

swiss2000_13853's avatar
swiss2000_13853
Icon for Nimbostratus rankNimbostratus
Feb 24, 2010

SSH and $PATH

Hi all

I'd like to run some commands on my LTM (10.0.1) via ssh. Problem is that these commands located in a directory which is not in the $PATH:

 
 $ssh user@f5ltm.company.com 'testcmd' 
 bash: testcmd: command not found 
 

 
 $ssh user@f5ltm.company.com 'echo $PATH' 
 /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
 

Does anybody know how to modify this PATH for SSH-Logins without shell exec?

I also tried the following setting in the sshd_config:

PermitUserEnvironment yes

and created a ~/.ssh/environment file with the PATH definition. That also didn't work.

Any other ideas?

Regards

Marc
  • I've not looked at it in a long while but I would try adding something like export PATH=$PATH:/your/dir/here to the root .bashrc file. I wouldn't mess with /etc/profile here, as it's liable to get clobbered on upgrade...

     

     

    -Matt
  • Hi Matt

     

     

    Thanks for your input. But $PATH is still the same, it doesn't seem to take effect.

     

     

    Any other suggestions?

     

     

    Regards

     

    Marc
  • Marc,

     

     

    As a workaround, try this:

     

     

     

    $ssh user@f5ltm.company.com '. ~/.bashrc; testcmd'

     

     

     

     

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Nice one...

     

     

    ssh user@myhost 'echo -e "before: $PATH\n"; . ~/.bashrc; echo "after: $PATH"'

     

    before: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

     

     

    after: /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

     

     

    Aaron
  • I would expect that the .bashrc gets correctly sourced on its own, but after looking at this there's a bit more going on. As expected ~/.bashrc gets sourced automatically when you're in an interactive shell. When you hit the box in non-interactive mode, you're getting trumped by /etc/bashrc, which calls a function called pathmunge (!) that is changing the path for non-interactive shell access.

     

     

    So your safest option is to do a re-source of the .basrc file as Humprey points out or to source a custom environment file separately so your new path will take. This last option may be a bit safer: now that we have to source a separate file anyhow, put the new environment script to source somewhere inside the /shared directory so you'll know for sure it'll stay intact through upgrades.

     

     

    -Matt
  • Mark_Crosland_2's avatar
    Mark_Crosland_2
    Historic F5 Account

     

    ssh user@host PATH=$PATH:/over/here:/over/there:/some/where/else yourCmd yourCmdArgs...