Operating System - Linux
1752795 Members
6565 Online
108789 Solutions
New Discussion юеВ

Re: ssh and environment variables

 
Leonid Mishkind
Frequent Advisor

ssh and environment variables

Hi all. I am running a script which uses ssh to run command on a Linux server ( The script runs on HP-UX ). I use the -l flag to connect with a certain user. ssh works fine, the thing is certain commands require some environment variables of the user . Is there any way to make ssh to load the environment of that user?

Thanks,
Leonid.
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: ssh and environment variables

Shalom Leonid,

I run a script on the command line that loads the users .profile or necessary variables. This should include TERM variable.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor

Re: ssh and environment variables

Whe executing a command like that, a full login isn't done, thus environment variables you'd usually associate with a login aren't there.

As you are running a command on the remote host, you could write a wrapper to set them, and call the wrapper instead.

Failing that, you could look at the 'PermitUserEnvironment' sshd configuration directive, and see if that fits your needs.
One long-haired git at your service...
Leonid Mishkind
Frequent Advisor

Re: ssh and environment variables

Thanks guys. Since there is only one variable I really need, I decided to export it before the execution of the command.

Leonid
Alexander Chuzhoy
Honored Contributor

Re: ssh and environment variables

It does so by default on my RH Linux machine, i.e. for example
when I do `ssh -l env`
I see the variables that are defined for that user in his shell. Isn't that what you need?
Leonid Mishkind
Frequent Advisor

Re: ssh and environment variables

Yes , This is what I need. But I guess my ssh is not configured to do so.