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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-15-2008, 07:17 PM
|
#1
|
LQ Newbie
Registered: Mar 2008
Posts: 27
Rep:
|
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
|
|
|
03-15-2008, 07:44 PM
|
#2
|
Member
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365
Rep:
|
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.
|
|
|
10-14-2008, 01:20 AM
|
#3
|
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305
Rep: 
|
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
|
|
|
10-14-2008, 02:24 AM
|
#4
|
LQ Newbie
Registered: Feb 2006
Location: Hamirpur
Distribution: Fedora, Suse, Debian
Posts: 6
Rep:
|
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.
|
|
|
10-14-2008, 09:29 AM
|
#5
|
Member
Registered: Sep 2003
Location: Colombia
Distribution: Debian
Posts: 220
Rep:
|
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..!
|
|
|
10-15-2008, 02:49 AM
|
#6
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
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.
|
|
|
10-16-2008, 07:23 AM
|
#7
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
Quote:
Originally Posted by thefountainhead100
... 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?
|
|
|
10-17-2008, 09:20 AM
|
#8
|
Member
Registered: Feb 2008
Posts: 47
Rep:
|
Will RSH work for you?
|
|
|
10-18-2008, 07:00 PM
|
#9
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
|
|
|
10-19-2008, 11:22 AM
|
#10
|
Member
Registered: Feb 2008
Posts: 47
Rep:
|
Quote:
Originally Posted by chrism01
|
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.
|
|
|
10-19-2008, 07:54 PM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
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 ...
|
|
|
10-20-2008, 04:32 AM
|
#12
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
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?
|
|
|
10-20-2008, 06:20 PM
|
#13
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
Absolutely, size and/or money doesn't automatically confer intelligence...

|
|
|
10-20-2008, 07:10 PM
|
#14
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Quote:
Originally Posted by archtoad6
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.
|
|
|
10-22-2008, 06:24 AM
|
#15
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
Agreed. I have used ssh-agent before & expect to start doing so again. I asked because the statement
Quote:
Originally Posted by thefountainhead100
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
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.
|
|
|
All times are GMT -5. The time now is 06:54 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|