How to ssh from a shell script ? For ppl who can write shell scripts.
ProgrammingThis 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.
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.
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..
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.
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.
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.
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 ...
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.