LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2008, 07:17 PM   #1
thefountainhead100
LQ Newbie
 
Registered: Mar 2008
Posts: 27

Rep: Reputation: 15
Unhappy How to ssh from a shell script ? For ppl who can write shell scripts.


I have asked related questions before. I am asking again because I donot have the answer yet.

Hoe to use ssh in a shell script? When I use it normally it asks for a password. SSH through RSA or DSA authentication does not work here in the machines I use. Is it possible to program the shell in such a way that the password is entered somewhere and the command doesnt ask for it during execution. (I have to run ssh in a loop). ssh does not come with any option to spicify the password in the single command line I guess.

A question for the shell programming experts out there..

Thanks for your time
Ash
 
Old 03-15-2008, 07:44 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
This does the job:

http://sourceforge.net/project/showf...roup_id=156659

However, you'll have to compile and install if from source to be able to integrate it into you shell script.
 
Old 10-14-2008, 01:20 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Smile

See this,


http://www.hostingrails.com/forums/wiki_thread/27

simple and easy solution. Even I learnt it from here.

Last edited by vikas027; 10-14-2008 at 11:53 PM. Reason: forgot to add url
 
Old 10-14-2008, 02:24 AM   #4
geek_comp
LQ Newbie
 
Registered: Feb 2006
Location: Hamirpur
Distribution: Fedora, Suse, Debian
Posts: 6

Rep: Reputation: 0
Use 'expect' command to automatically enter the username and password, if RSA key copying to target doesnt works.
in shell script use ssh as "ssh target_ip file_or_cmd_to_execute"
Thats it.
 
Old 10-14-2008, 09:29 AM   #5
Ricio
Member
 
Registered: Sep 2003
Location: Colombia
Distribution: Debian
Posts: 220

Rep: Reputation: 30
copy your rsa key.pub to the machine you want to log in, or use ssh-copy-id in the script... youll have to enter your password once and no more..!
 
Old 10-15-2008, 02:49 AM   #6
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
I've moved this thread to the programming forum because I think its more appropriate there since you are looking to do resolve your problem using a shell script.
 
Old 10-16-2008, 07:23 AM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by thefountainhead100 View Post
... SSH through RSA or DSA authentication does not work here in the machines I use. ...
Are you trying to say that ssh-agent won't work on these machines?
 
Old 10-17-2008, 09:20 AM   #8
OldGaf
Member
 
Registered: Feb 2008
Posts: 47

Rep: Reputation: 15
Will RSH work for you?
 
Old 10-18-2008, 07:00 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
don't use rsh: http://www.informit.com/articles/art...p=169465&rll=1
 
Old 10-19-2008, 11:22 AM   #10
OldGaf
Member
 
Registered: Feb 2008
Posts: 47

Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Well..... I don't know.

I think it all comes down to how secure your whole system is.

I work for one of the worlds biggest investment companys.
We have an IT budget of over $1 billion a year. If it was that big an issue, you can bet we would change it.
 
Old 10-19-2008, 07:54 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I've worked for some very large ones myself, eg Merchant Banks
Obviously its up to 'you', but no matter how big the company, it doesn't make the protocol any safer, and you can do the same work with ssh/scp/sftp ...
 
Old 10-20-2008, 04:32 AM   #12
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Running RSH is like leaving your house keys under the welcome mat.

RTEFA, Read the excellent article, it begins:
"Running RSH is like leaving your house keys under the welcome mat."

Printer friendly link:
http://www.informit.com/articles/pri....aspx?p=169465

It goes on to answer the objection, "But our network is strictly switched, and security is good. No one can penetrate our perimeter!"; as well as to discuss how to move to ssh.

&BTW, since when were banks smart or long sighted?
 
Old 10-20-2008, 06:20 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Absolutely, size and/or money doesn't automatically confer intelligence...
 
Old 10-20-2008, 07:10 PM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Quote:
Originally Posted by archtoad6 View Post
Are you trying to say that ssh-agent won't work on these machines?
Archtoad. Ssh-agent is for unlocking the private key of the client (and for the client). If you use public key authentication and not password challenge, then ssh-agent will work in allowing you to enter the passphrase once per shell session. You can log into different servers as well.

The OP mentioned password instead of passphrase. The password authentication is being requested by the server, such as using PAM instead of the passphrase which is used locally on the client to unlock the client's own private key.
 
Old 10-22-2008, 06:24 AM   #15
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Agreed. I have used ssh-agent before & expect to start doing so again. I asked because the statement
Quote:
Originally Posted by thefountainhead100 View Post
SSH through RSA or DSA authentication does not work here in the machines I use.
did not make sense to me coming in the middle of
Quote:
Originally Posted by thefountainhead100 View Post
Hoe to use ssh in a shell script? When I use it normally it asks for a password. SSH through RSA or DSA authentication does not work here in the machines I use. Is it possible to program the shell in such a way that the password is entered somewhere and the command doesnt ask for it during execution. (I have to run ssh in a loop). ssh does not come with any option to spicify the password in the single command line I guess.
Everything else in that paragraph says that ssh w/ a password is working, but not conveniently; the line about "SSH ... authentication" which I quoted separately says something doesn't work at all. Since ssh-agent is a standard way around the inconvenience s/he seems to be complaining about, I inferred that the something which doesn't work might be ssh-agent, but I needed clarification before I assumed that that idea is correct.

It would be nice if OP would clarify.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help!Write xml document with shell scripts wmh830621 Programming 4 08-11-2006 04:55 AM
Can't run shell scripts I write? JustinCoyan Slackware 2 08-06-2004 12:50 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM
ssh using shell scripts Alek Linux - Networking 4 09-05-2003 01:28 PM
SSH using shell scripts Alek Linux - General 2 08-28-2003 02:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration