Linux, problem with remote script and environment variables

Posted on 2013-12-20
Medium Priority
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
[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
[root@xxclnt2 .ssh]# cat environment | wc -l
[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
[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
[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
[root@xxclnt1 home]#

Open in new window

So I only see 46 environment variables

What did I do wrong ?

Question by:Los Angeles1
LVL 19

Accepted Solution

xterm earned 1000 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.
LVL 10

Assisted Solution

acbxyz earned 1000 total points
ID: 39732656

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

597 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