Solved

Linux, ssh and environment initialization  (with and without scripts)

Posted on 2013-12-19
5
318 Views
Last Modified: 2013-12-20
If I use the following command

[root@xxclnt1 sbin]# sshpass -p 'xxxx' ssh root@xxclnt1 /sbin/test.sh

Open in new window


This command will have a different environment than a command such as the following where I ssh into the clinet, and then manually perform the script

[root@xxclnt1 sbin]# sshpass -p 'xxxx' ssh root@xxclnt1 
/sbin/test.sh

Open in new window



This appears difficult to fix.  Is there an easy way to get the remote ssh scripts to have the same command environment as the ssh sessions run without a command file

Thanks
0
Comment
Question by:Los Angeles1
  • 3
  • 2
5 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39730403
There are two ways to achieve this.

1)

ssh reads ~/.ssh/environment on the target server, and adds lines of the format "VARNAME=value" to the environment if the file exists and users are allowed to change their environment.

sshd_config on the target machine must have set "PermitUserEnvironment yes" to make this work.

2)

The client can send environment variables. To make this work the server's sshd_config must have defined which variables to accept by means of  "AcceptEnv" and the client's ssh_config must have specified which variables to send to the target machine from the local environment by means of "SendEnv".

See the sshd_config and ssh_config manpages for more detail.
0
 

Author Comment

by:Los Angeles1
ID: 39730522
wmP

In regards to method 1>

I do not have a .ssh/environment

Is there any yum install or other method in which I can make this happen

Thanks
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39730588
~/.ssh/environment

is just a text file in the .ssh subdirectory of the home directory of the target user on the target machine - to be created by you.

It must contain entries in the format

MYVAR=myvalue

one per line.

ssh will add these variables to the target user's environment before executing the batch commands.
0
 

Author Comment

by:Los Angeles1
ID: 39730740
1> So if I get you right, if I ssh in as root, I should create the following file

/home/root/.ssh/environment

2> Next I assume I should ssh into the target, and perform the command

set

Open in new window


and cut and paste that into the file created above

Is this all correct ?

Thanks
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39730752
You can do it that way, correct. It seems a bit overdone, because some variables already exist even in the ssh batch environment, but it's not wrong nonetheless.

Don't copy and paste - run

set > ~/.ssh/environment

Please remember that the sshd server config on the target machine must contain "PermitUserEnvironment yes" to make this work. Don't forget to restart the sshd server after making changes!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now