Operating System - HP-UX
1754964 Members
3250 Online
108828 Solutions
New Discussion

env variable different when logon to system vs ssh system "env"

 
SOLVED
Go to solution
Sammy_2
Super Advisor

env variable different when logon to system vs ssh system "env"


I have noticed my env gets setup different depending on how I log into the system. Here is an example to issistrate what I am trying to figureout.

1. >ssh ojrdres1 env (then give passwd)
• Env listing is very short .. it is not reading my .profile
2. >ssh ojrdres1 (then give passwd)
3. >env
• Env listing is what I expect .. it is reading my .profile.

Do you know how I can perform 1 and get it to read my .profile, and the system .profile?
good judgement comes from experience and experience comes from bad judgement.
4 REPLIES 4
Mel Burslan
Honored Contributor

Re: env variable different when logon to system vs ssh system "env"

Short of recompiling openssh from available source code, I am not sure if you can do this. But again this information is coming from the times ssh was v3.x Now that the version numbers are upto 5 something, there might be some major changes implemented that I am not aware of.

But when you are in remote command execution mode, i.e., your option (1), you will not get your ENVIRONMENT variable like you get during an interactive session. You need to call almost every each command by its absolute path unfortunately.
________________________________
UNIX because I majored in cryptology...
Steven Schweda
Honored Contributor

Re: env variable different when logon to system vs ssh system "env"

With my weak psychic powers, I know
approximately nothing about _your_ "the
system", but on mine, "man ssh" says:

[...]
If command is specified, it is executed on the remote host instead of
a login shell.
[...]


> Do you know how I can perform 1 and get it
> to read my .profile, and the system
> .profile?

I wouldn't bet on how many things won't work
as expected, but you could try something
like:

echo env | ssh ojrdres1

That is, no "command" in the ssh command, so
it will read from stdin. For example:


dyi # ssh dyi 'echo $EDITOR'

dyi #


dyi # echo 'echo $EDITOR' | ssh dyi 2> /dev/null
Last successful login: Wed Jan 5 16:51:22 CST 2011 dyi.antinode.info
Last authentication failure: Thu Oct 14 12:59:57 CDT 2010 dyi.antinode.info
You have mail.


Value of TERM has been set to "".
WARNING: YOU ARE SUPERUSER !!

vi
dyi #

Fishing the desired result ("vi") out of the
log-in noise is only one of the problems with
a method like this.


As usual, some basic information about the
system(s) involved might be helpful:

uname -a
ssh -V
Sammy_2
Super Advisor

Re: env variable different when logon to system vs ssh system "env"

Additional information about 2 systems.

SSH From
=====================
[root@ojrdlesapp21 ~]# uname -a
Linux ojrdlesapp21 2.6.18-194.11.1.el5 #1 SMP Tue Jul 27 05:45:06 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

[root@ojrdlesapp21 ~]# ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
[root@ojrdlesapp21 ~]#


SSH TO
=========

ojrdhes3::ESDEV:/home/karl030> uname -a
HP-UX ojrdhes3 B.11.11 U 9000/800 522788742 unlimited-user license

ojrdhes3::ESDEV:/home/karl030> ssh -V
OpenSSH_3.9, OpenSSL 0.9.7d 17 Mar 2004
HP-UX Secure Shell-A.03.91.002, HP-UX Secure Shell version
ojrdhes3::ESDEV:/home/karl030>



Thanks
good judgement comes from experience and experience comes from bad judgement.
Doug O'Leary
Honored Contributor
Solution

Re: env variable different when logon to system vs ssh system "env"

Hey;

The whole point of the remote command execution is to have a limited shell so you can run commands very quickly. If you need a specific environment for a specific command, you can set up a wrapper script:

#!/bin/ksh

. ./.profile
${my_command_of_choice}
#eof

for instance, then call that via :

ssh ${host} ~/bin/my_cmd

lastly, if you really want an environment for your commands, you can update the ~/.ssh/environment file - referenced in the ssh man page:

Additionally, ssh reads ~/.ssh/environment, and adds lines of the format "VARNAME=value" to the environment if the file exists and users are allowed to change their environment. For more information, see the PermitUserEnvironment option in sshd_config(5).

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html