The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
VSFTPD Public Key Help mokachoka UNIX for Dummies Questions & Answers 0 10-23-2009 08:40 AM
RSA decrypt with public key ? Sushma Y Linux 3 04-13-2009 09:02 AM
NIM server setup on etherchannel setup environment pdtak AIX 1 05-28-2008 05:54 PM
SSH - Public key rahulrathod UNIX for Advanced & Expert Users 6 05-31-2007 11:37 AM
ssh public keys ghost01 UNIX for Dummies Questions & Answers 1 06-30-2006 02:59 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-28-2009
haroon_a haroon_a is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 17
ssh public key setup questions.

Hi all,

I have N number of AIX hosts, where I need to login frequently and do some routine tasks (run some scripts). I need to setup ssh public/private key, so I can auto-login via a master (wrapper) script and run each script in each server.

I am trying to setup/generate ssh keys, but am facing some problems. Here's what I have done:

- Generate ssh keys, as follow:

Code:
haroon_a@myhost1:/home/haroon_a/.ssh > ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haroon_a/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/haroon_a/.ssh/id_rsa.
Your public key has been saved in /home/haroon_a/.ssh/id_rsa.pub.
The key fingerprint is:
a2:92:49:ed:a8:c6:18:9d:ec:64:f5:fe:70:e7:09:fe haroon_a@myhost1
haroon_a@myhost1:/home/haroon_a/.ssh > ls -ltr
total 3
-rw-r-----   1 nbkysrj  staff           232 Oct 28 07:59 id_rsa.pub
-rw-------   1 nbkysrj  staff           887 Oct 28 07:59 id_rsa
haroon_a@myhost1:/home/haroon_a/.ssh > scp id_rsa.pub haroon_a@myhost2:.ssh/authorized_keys2

- So now id_rsa.pub is copied over to my host2:/home/haroon_a/.ssh/.
- When I try to do an ssh login either from host1 to host2 or from host2 to host1, the ssh login doesn't work. It still asks me for password.

- Can someone tell me what I'm missing here?

Thanks in advance.


Haroon A.

---------- Post updated at 11:03 AM ---------- Previous update was at 10:19 AM ----------

I got the ssh auto-login to work. But here's my other question now:

- Like I mentioned, I have N number of hosts, where I need to run some scripts on a regular basis. So, here's what I have in mind.

1. Create a script in host1 to wrap arround all other scripts in other hosts (host2, host2, host4) and execute each scripts in all other hosts. i.e. something like this:


Code:
ssh to host2
execute script1
execute script2
 
ssh to host3
execute script1
execute script2
 
ssh to host4
execute script1
execute script2

But as soon as the ssh host2, is executed--the first line--, then I am taken to host2, and I'm out of the script (which is in host1).

Am I making any sense? Please advise...

Thanks.
  #2 (permalink)  
Old 10-28-2009
zxmaus's Avatar
zxmaus zxmaus is offline Forum Staff  
Moderator
  
 

Join Date: May 2008
Location: /etc/objrepos
Posts: 304
Hi,

the good news - your script works It does exactly what you tell it to do.

The bad news - if you want just remote execution you should rather use the rsh command facilities rather than ssh and than pull the output. Obviously bad for security.

Kind regards
zxmaus
  #3 (permalink)  
Old 10-28-2009
haroon_a haroon_a is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 17
Quote:
Originally Posted by zxmaus View Post
Hi,

the good news - your script works It does exactly what you tell it to do.

The bad news - if you want just remote execution you should rather use the rsh command facilities rather than ssh and than pull the output. Obviously bad for security.

Kind regards
zxmaus
Thanks for the hints and advise. I'll look into rsh.

In the meantime, I am working on my script, and want to re-use portions of my code (BTW, I'm not an expert in shell scripting), so I decided to use a function. So, here's what I'm trying to use function, but I can't get it to work, Please bare with me.

Code:
#!/bin/sh
#some codes here
...
printThisWord "Hey, You printed me!!"
...
# some more code here
 
printThisWord () {
echo "$1"
}

However, when I run my script, it says:

Code:
myscript.sh[32]: printThisWord:  not found

The rest of the script gets executed.

Please advise...

Thanks.
  #4 (permalink)  
Old 10-29-2009
garethr garethr is offline
Registered User
  
 

Join Date: May 2009
Location: England
Posts: 92
In the shell script, printThisWord () {...} needs to come before you first try to call printThisWord.

On the ssh side, you can run commands remotely as follows:

Code:
ssh user@remotehost "df -k ; ls /"

  #5 (permalink)  
Old 10-29-2009
haroon_a haroon_a is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 17
Quote:
Originally Posted by garethr View Post
In the shell script, printThisWord () {...} needs to come before you first try to call printThisWord.

On the ssh side, you can run commands remotely as follows:

Code:
ssh user@remotehost "df -k ; ls /"

Thanks you. It worked, when I moved the function before its call.

I have another question:

I want to cancatenate value of some variables, and pass it to another functin. i.e.

Code:
aFunction() {
echo "$1"
}
 
msg1="some message\n"
msg2="some other message\n"
msg3="even some more message\n"
 
msgs="$msg1 $msg2 $msg3"
 
aFunction $msgs

But when I run my script, the output is only the first line, rather the first word. I guess it does it because $1 is for the first argument, and hence it only takes "some" in this case.

Can someone tell me how to pass value of $msgs which is 3 lines into a function and read the entire value (3 lines) from within my function?

Thanks,


Please advise...
  #6 (permalink)  
Old 10-29-2009
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,633
The reason is you do not protect your variable by quoting it:


Code:
afunction "$msg"

should do the trick. You might have to quote the variable inside the function too to preserve its contents. It is generally good style to quote as exactly as possible, even if it is not absolutely necessary.

[Moderator-mode on]
Please notice that we do not have a shortage in thread slots here, so please open a new thread if you have a new question.

We are trying to build a knowledge base. That means, if some other user has the same problem like you ideally he should be able to find the solution without having to ask the question again, just by searching the forum.

Having several independent problems discussed in a single thread does not further this cause, because a user with your shell problem is likely not searching for a thread about ssh configuration.

Nobody will think bad about you if have several different problems and open several different threads, one for each of them. Quite contrary this is what we ask you to do.

Another point is forum specialization: you might notice that there are different parts of the forum, one for AIX and one for shell programming for instance. Sometimes it is difficult to decide where a thread should go, but in this case it would have been easy, but now we have a thread which deals with two (or three) different problems and each part would belong to a different part of the forum.

I hope you understand and i ask you follow these forum behavior standards more carefully in the future. Thank you.

[/Moderator Mode off]

I hope this helps.
  #7 (permalink)  
Old 4 Weeks Ago
haroon_a haroon_a is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 17
Quote:
Originally Posted by bakunin View Post
The reason is you do not protect your variable by quoting it:


Code:
afunction "$msg"

should do the trick. You might have to quote the variable inside the function too to preserve its contents. It is generally good style to quote as exactly as possible, even if it is not absolutely necessary.

[Moderator-mode on]
Please notice that we do not have a shortage in thread slots here, so please open a new thread if you have a new question.

We are trying to build a knowledge base. That means, if some other user has the same problem like you ideally he should be able to find the solution without having to ask the question again, just by searching the forum.

Having several independent problems discussed in a single thread does not further this cause, because a user with your shell problem is likely not searching for a thread about ssh configuration.

Nobody will think bad about you if have several different problems and open several different threads, one for each of them. Quite contrary this is what we ask you to do.

Another point is forum specialization: you might notice that there are different parts of the forum, one for AIX and one for shell programming for instance. Sometimes it is difficult to decide where a thread should go, but in this case it would have been easy, but now we have a thread which deals with two (or three) different problems and each part would belong to a different part of the forum.

I hope you understand and i ask you follow these forum behavior standards more carefully in the future. Thank you.
[/Moderator Mode off]

I hope this helps.
Absolutly correct, bak! That simple, yet important--at least in my case--trick, did the job. Thanks alot.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0