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
Solved

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

Posted on 2013-12-19
5
323 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

789 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