Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

SSH Automation?

by raflach (Pilgrim)
on Sep 27, 2000 at 02:16 UTC ( [id://34126]=perlquestion: print w/replies, xml ) Need Help??

raflach has asked for the wisdom of the Perl Monks concerning the following question:

My problem is as follows:
1. I have a machine that I can only access via ssh2.
+2. I need to write a script that can be run from cron, that will open a connection to that machine via ssh2 without any user intervention.
+3. Input redirection doesn't work for the required password in ssh2. (Interpretation: Everything I have tried so far has failed to automate the entry of the password)
=
4. Problem: How can I automate this process?
Are there modules, or better yet a code snippet that will ease the writing an ssh client in perl so that I can bypass this problem?
Is there some other way around this that I am just totally missing?

Replies are listed 'Best First'.
Re: SSH Automation?
by isotope (Deacon) on Sep 27, 2000 at 02:34 UTC
    Actually, you might want to see the manpages for ssh-keygen and perhaps ssh-agent. Basically you create an RSA key with no password (or use ssh-agent to keep the decrypted key in memory for your process), then run your script without having to deal with the password prompt at all. You'll be using key authentication instead of password auth.

    Update: You might also look at Expect, but using a key is generally better than keeping passwords around in crontabs and/or scripts.

    --isotope
      Ok, based on a brief glance at the recommended manpages, that will probably solve the problem.
      For curiosity's sake (and in case it doesn't), Anyone want to take another potshot at this?
        The password is almost certainly being asked of /dev/tty, not standard input. This means that you need to use a pseudo-tty to fake out the program. Pseudo-ttys are managed by Expect and IO::Tty.

        -- Randal L. Schwartz, Perl hacker

        merlyn already offered a solution, but in this case I can say that it does solve the problem. I have a lot of programs which use this to great effect, saving a lot of headaches. (As a security note, why bother having a password for the account at all?:-)
Re: SSH Automation?
by casiano (Pilgrim) on Jun 06, 2008 at 12:18 UTC
    You can find a description on how to set automatic authentication via SSH in GRID::Machine::perlparintro.
    Once is set you can use GRID::Machine in your script to have a Perl interpreter running under your control in the remote side

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://34126]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found