Discussion:
Fixing $PATH programmatically for non-interactive SSH
(too old to reply)
Rémi PALANCHER
2010-03-26 15:01:53 UTC
Permalink
Hi there,

I'm looking for a way to fix programmatically the $PATH after an
incoming SSH connection, not only for remote interactive shells, but
for remote command execution also.

I'm using Debian Lenny with , and currently I have :

***@host:~$ ssh -V
OpenSSH_5.1p1 Debian-5, OpenSSL 0.9.8g 19 Oct 2007
***@host:~$ ssh localhost
[...]
***@host:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/myowndir
***@host:~$ exit
***@host:~$ ssh localhost 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

I would like to add /myowndir to the $PATH for remote command
execution, as well as for remote login shells.

As far I've investigated, $PATH is fixed by /etc/profile for interactive
connection. But unfortunately, for remote command execution, this script
is not executed.

I would like to add this dir to $PATH for all users except the famous
one with uid 0. So, I guess I can't use those basics key/value files
such as /etc/environment or ~/.ssh/environment.

Is there any simple way to deal with such constraints in OpenSSH?
Intuitively, I was thinking of well-thought combination of 'UsePAM yes'
and modules in /etc/pam.d/sshd?

Thanks in advance for any kind of help,
--
Rémi PALANCHER IJD/SMI
Systems and networks administrator on Grid'5000
INRIA Saclay Building H
tel: +33 1 74 85 42 45 Office 015
Greg Wooledge
2010-03-26 16:18:38 UTC
Permalink
Post by Rémi PALANCHER
I would like to add /myowndir to the $PATH for remote command
execution, as well as for remote login shells.
One way is to put the PATH=... command in ~/.ssh/environment and then
make sure PermitUserEnvironment is set to yes in the sshd_config.
Post by Rémi PALANCHER
As far I've investigated, $PATH is fixed by /etc/profile for interactive
connection. But unfortunately, for remote command execution, this script
is not executed.
That's correct.
Post by Rémi PALANCHER
I would like to add this dir to $PATH for all users except the famous
one with uid 0. So, I guess I can't use those basics key/value files
such as /etc/environment
That's a Debianism, or at least a Linuxism. It's a configuration file
that's read by PAM (when readenv=1 appears in the matching PAM config file
entry). You -could- use that, in theory, but it's not a shell script.
So you can't do things like PATH=$PATH:/myowndir but rather, you have
to type out the entire PATH=/foo:/bar:/myowndir value. It's pretty bad.

(I once wanted to use it to set MAIL=$HOME/Maildir/ globally, but you
simply can't do that with it. I gave up. It's nigh useless.)
Post by Rémi PALANCHER
or ~/.ssh/environment.
This is the appropriate place, as far as I can tell.
Post by Rémi PALANCHER
Is there any simple way to deal with such constraints in OpenSSH?
Intuitively, I was thinking of well-thought combination of 'UsePAM yes'
and modules in /etc/pam.d/sshd?
Debian's sshd_config has "UsePAM yes" by default. So, if you do decide
to go with the /etc/environment thing, it ought to work, as far as I know.
Charles Bradshaw
2010-03-26 16:22:29 UTC
Permalink
Hi
Post by Rémi PALANCHER
I'm looking for a way to fix programmatically the $PATH after an
....
This might be what you're looking for:

SSH The Secure Shell, The Definitive Guide.
8.2.6 Setting Environment Variables - page 308

Loading...