Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Net::SSH::Perl failback connection

by tweetiepooh (Friar)
on Nov 10, 2010 at 10:44 UTC ( #870547=note: print w/ replies, xml ) Need Help??


in reply to Net::SSH::Perl failback connection

I have worked a solution. It's not very good in that it stores passwords in the clear in the program and it may have other issues but it does seem to work.

#!/usr/bin/perl -w use strict; use Net::SSH::Perl; my @logins = ( [undef,undef], ["myname","mypass"], ["local","localpw"], ["root",undef], ["root","pass1"], ["root","pass2"], ... ["root","passn] ); my $ssh; <open file with server list> while (my $server = <read from file>) { chomp $server; print $server; if (SSHConnect($server)) { <do some work> } } sub SSHConnect { my $server = shift; my $return = 0; $ssh = Net::SSH::Perl->new($server,protocol=>'2,1'); foreach (@logins) { my ($u,$p) = @{$_}; eval { $ssh->login(); }; if (!$@) { $return = 1; last; }; return $return; }
A better solution may be to put login credentials into the server list (and encrypt this) but at this time I don't know what will work for each server and things can change.


Comment on Re: Net::SSH::Perl failback connection
Download Code
Replies are listed 'Best First'.
Re^2: Net::SSH::Perl failback connection
by afoken (Prior) on Nov 10, 2010 at 22:32 UTC

    Use public keys instead of passwords. Use sudo instead of logging in directly as root. In a next step, forbid root logins and password authentication in sshd_config.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://870547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2015-07-31 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls