Solved

Linux, problem with remote script and environment variables

Posted on 2013-12-20
2
384 Views
Last Modified: 2013-12-20
I am using RHEL 6.5

I am trying to use ssh to perform a command file
on a target machine.

In order to do this I have attempted to set up
the sshd environment on the target machine (xxclnt2)

However, it appears I was unsuccessful

First I go to the target machine and set the
~/.ssh/environment file to contain the environment
variables contained in a normal session:

[root@xxclnt2 .ssh]# pwd
/home/root/.ssh
[root@xxclnt2 .ssh]# set > /home/root/.ssh/environment
[root@xxclnt2 .ssh]#

Open in new window


Then I record the number of environment variables
that were placed in this file:

[root@xxclnt2 .ssh]# pwd
/home/root/.ssh
[root@xxclnt2 .ssh]# cat environment | wc -l
66
[root@xxclnt2 .ssh]#

Open in new window


Then I make sure the PermitUserEnvironment is set
properly in the sshd config file:

[root@xxclnt2 ssh]# pwd
/etc/ssh
[root@xxclnt2 ssh]# grep "PermitUserEnvironment yes" sshd_config
PermitUserEnvironment yes
[root@xxclnt2 ssh]#

Open in new window


Finally I restart the sshd on the target machine:

[root@xxclnt2 ssh]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@xxclnt2 ssh]#

Open in new window


I create a script named /home/test that counts the environment variable lines:

[root@xxclnt2 home]# pwd
/home
[root@xxclnt2 home]# cat test
set | wc -l
[root@xxclnt2 home]#

Open in new window


Now I switch to the remote machine and remotely start
the /home/test

[root@xxclnt1 home]# sshpass -p 'xxxx' ssh root@xxclnt2 /home/test
46
[root@xxclnt1 home]#

Open in new window


So I only see 46 environment variables

What did I do wrong ?

Thanks
0
Comment
Question by:Los Angeles1
2 Comments
 
LVL 19

Accepted Solution

by:
xterm earned 250 total points
ID: 39732611
You didn't do anything wrong - there are certain variables that only get set if you stay logged in.

One example is SSH_TTY which you will see if you do "set | grep _TTY" while logged into xxclnt2- however if you do "ssh xxclnt2 set | grep _TTY" you won't get a result.
0
 
LVL 10

Assisted Solution

by:acbxyz
acbxyz earned 250 total points
ID: 39732656
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question