Solved

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

Posted on 2013-12-19
5
316 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
Comment Utility
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
Comment Utility
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
Comment Utility
~/.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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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 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 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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now