RE: [Ssh-sftp-perl-users] Interfacing with network appliance through ssh
Brought to you by:
dbrobins
From: Eric L. <net...@er...> - 2006-03-22 16:44:11
|
Wouldn't it just be simpler to use public key auth? Do you really want to have scripts with your passwords hard coded? Have you tried doing the login as a single step, like so: $ssh->login($user, $pass); Here's a sample of one I have working using public key: #!/usr/bin/perl Use strict; Use Net::SSH::Perl; My @ident = ("/home/user/.ssh/id_dsa"); my %params = ( protocol => 2, interactive => 0, identity_files => [@ident], debug => 0, options => [ "BatchMode yes", "AuthenticationSuccessMsg no", "ForwardX11 no", "ForwardAgent no" ] ); my $server = $ARGV[0]; &sshconnect($server); my ($stdout, $stderr, $exit) = $ssh->cmd("ls"); print "$stdout\n"; if (! $ssh) { print "Unable to establish ssh connection to: $server\n"; } else { print "Successfully established ssh connection to: $server\n"; } sub sshconnect { my $server = $_[0]; our $ssh = Net::SSH::Perl->new("$server", %params); $ssh->login("user"); } Here is an example using username/password login: #/usr/bin/perl use strict; use Net::SSH::Perl; use vars qw($ssh); my %params = ( protocol => 2, interactive => 0, debug => 0, options => [ "BatchMode yes", "AuthenticationSuccessMsg no", "ForwardX11 no", "ForwardAgent no" ] ); my $pass = "password"; my $server = $ARGV[0]; &sshconnect($server); my ($stdout, $stderr, $exit) = $ssh->cmd("ls"); print "$stdout\n"; if (! $ssh) { print "Unable to establish ssh connection to: $server\n"; } else { print "Successfully established ssh connection to: $server\n"; } sub sshconnect { my $server = $_[0]; our $ssh = Net::SSH::Perl->new("$server", %params); $ssh->login("user", $pass); } Hope this helps. > -----Original Message----- > From: ssh...@li... > [mailto:ssh...@li...] On > Behalf Of Matthew J. Salerno > Sent: Wednesday, March 22, 2006 8:55 AM > To: ssh...@li... > Subject: [Ssh-sftp-perl-users] Interfacing with network > appliance through ssh > > I have been going nuts trying to get this to work. > Any help is appreciated. > > > I need to automate the process of logging in to a network > appliance and executing a few commands. The network > appliance uses: OpenSSH 3.8.1 > > The system I am executing from is using: > Redhat Linux > Net::SSH::Perl 1.30 > Perl 5.8.5 > > Here is the login process, step-by-step: > # ssh username1@10.10.10.15 > > Then I get prompted for another username as expected. > > Welcome to Webstream Server > > Username: <Enter Username> > > Get prompted for > Password: <Enter Password> > > This is where I am stuck. I have been working on the login > process for a few days now, and I still cant pass the server > the password. I can easily get to the point where it prompts > for the password, but it does not work. Any help would be > greatly appreciated. > Here is what I have so far: > > #!/usr/bin/perl -w > use strict; > use Net::SSH::Perl; > > my %params; > $params{"debug"} = 0; > $params{"port"} = 22; > $params{"protocol"} = 2; > $params{"interactive"} = 0; > $params{"compression"} = 0; > $params{"PreferredAuthentications"} = 'password'; > $params{"PubkeyAuthentication"} = 'no'; > $params{"RSAAuthentication"} = 'no'; $params{"use_pty"} = 0; > > my $host = "10.10.10.15"; > my $ruser = "username1"; > my $user = 'username2'; > my $pw = 'mypassword'; > > my $ssh = new Net::SSH::Perl($host, %params) || > die "Cannot Connect to system $! $@\n"; > > print "Logging In\n"; > $ssh->login($ruser) || die "Cannot Login $! $@\n"; > > $ssh->register_handler("stdout", sub { > my($channel, $buffer) = @_; > my $str = $buffer->bytes; > print "\nSTR: $str\nEND\n\n"; > > if ($str =~ /Username: $/) { > print "USER2\n"; > $channel->send_data("$user\n$pw\n"); > } > > elsif ($str =~ /Password/i) { > print "\nPASSWORD2\n"; > $channel->send_data($pw,"\n"); > } > }); > > my ($stdout, $stderr, $exit) = $ssh->cmd($user); > > print "\n\nSTDOUT - $stdout\n" if $stdout; print "STDERR - > $stderr\n" if $stderr; print "EXIT $exit\n" if $exit; > > exit; > > ---------- > The results are: > > Logging In > > STR: Welcome to Webstream Server > > Username: > END > > USER2 > > STR: Password: > Could not read password. > Authenticating [username2]..... > Authentication Failed. Good bye. [0x9] > > END > > PASSWORD2 > EXIT 255 > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection > around http://mail.yahoo.com > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking > scripting language > that extends applications into web and mobile media. Attend > the live webcast > and join the prime developer group breaking into this new > coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720& dat=121642 > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > |