?
Solved

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

Posted on 2013-12-19
5
Medium Priority
?
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Fine Tune your automatic Updates for Ubuntu / Debian
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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