Forum Discussion
swiss2000_13853
Nimbostratus
Feb 24, 2010SSH 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
6 Replies
- L4L7_53191
Nimbostratus
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 - swiss2000_13853
Nimbostratus
Hi Matt
Thanks for your input. But $PATH is still the same, it doesn't seem to take effect.
Any other suggestions?
Regards
Marc - hwidjaja_37598
Altostratus
Marc,
As a workaround, try this:
$ssh user@f5ltm.company.com '. ~/.bashrc; testcmd' - hoolio
Cirrostratus
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 - L4L7_53191
Nimbostratus
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_2Historic F5 Account
ssh user@host PATH=$PATH:/over/here:/over/there:/some/where/else yourCmd yourCmdArgs...
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
