LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to ssh from a shell script ? For ppl who can write shell scripts. (http://www.linuxquestions.org/questions/programming-9/how-to-ssh-from-a-shell-script-for-ppl-who-can-write-shell-scripts-628333/)

thefountainhead100 03-15-2008 07:17 PM

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

harry edwards 03-15-2008 07:44 PM

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.

vikas027 10-14-2008 01:20 AM

See this,


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

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

geek_comp 10-14-2008 02:24 AM

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.

Ricio 10-14-2008 09:29 AM

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..!

reddazz 10-15-2008 02:49 AM

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.

archtoad6 10-16-2008 07:23 AM

Quote:

Originally Posted by thefountainhead100 (Post 3089892)
... 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?

OldGaf 10-17-2008 09:20 AM

Will RSH work for you?

chrism01 10-18-2008 07:00 PM

don't use rsh: http://www.informit.com/articles/art...p=169465&rll=1

OldGaf 10-19-2008 11:22 AM

Quote:

Originally Posted by chrism01 (Post 3315063)

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.

chrism01 10-19-2008 07:54 PM

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 ...

archtoad6 10-20-2008 04:32 AM

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?

chrism01 10-20-2008 06:20 PM

Absolutely, size and/or money doesn't automatically confer intelligence...
:)

jschiwal 10-20-2008 07:10 PM

Quote:

Originally Posted by archtoad6 (Post 3312108)
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.

archtoad6 10-22-2008 06:24 AM

Agreed. I have used ssh-agent before & expect to start doing so again. I asked because the statement
Quote:

Originally Posted by thefountainhead100 (Post 3089892)
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 (Post 3089892)
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 04:05 PM.