Re: [Ssh-sftp-perl-users] help needed for SFTP,SCP keys
Brought to you by:
dbrobins
From: Heiko J. <ja...@hb...> - 2008-07-09 13:16:03
|
Am Mittwoch, den 09.07.2008, 04:18 -0700 schrieb Vikas Poonia: > First thanks a lot. Here i am sending the code which i m executing and > the error which i am getting. > > #!/usr/bin/env perl -w > use Net::SSH2; > use Net::SCP; > use warnings; > use strict; > my $z_host="10.153.178.170"; > my $z_user="kls_dev"; > my $z_auth="xxx"; > my $ssh2 = Net::SSH2->new(); > $ssh2->debug(1); > $ssh2->connect($z_host) or die "Unable to connect Host $@ \n Der Host > $@ ist nicht erreichbar! \n"; > $ssh2->auth_publickey("kls_dev",'/opt/mqm/home/kls_dev/vikas/id.pub','/opt/mqm/home/kls_dev/vikas/id' ) or die "Not able to Login"; > #########$ssh2->scp_put("vikas", "mist-scp-key") or die "Unable to > transfer file $@ \n"; > > Where Public key= '/opt/mqm/home/kls_dev/vikas/id.pub' > and Private key = '/opt/mqm/home/kls_dev/vikas/id' > > When i run this program on my perl i m getting ther error > > bash-3.00$ ./vikas-scppwd > Not able to Login at ./vikas-scppwd line 15. > Net::SSH2::DESTROY object 0x20b118 > > Can u please let me know what needs to be done. Thanks in Advance Please try this code after replacing the appropriate values (user, host, keyfile names, testfile): -- snip -- #!/usr/bin/perl use strict; use warnings; use Net::SSH2; my $host = 'platon'; my $user = 'jansen'; my $keypath = '/home/jansen/.ssh/'; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); eval { $ssh2->connect($host) }; if ($@) { die "Unable to connect host '$host': $@"; } my $auth = $ssh2->auth_list($user); # works if connection succeeded if ( index( $auth, 'publickey' ) == -1 ) { die "Remote host '$host' does not support 'publickey' authentication!\n"; } if ( $ssh2->auth_publickey( $user, $keypath . 'id_rsa.pub', $keypath . 'id_rsa' ) ) { warn "Authentication succeeded\n" if $ssh2->auth_ok(); } else { die "Authentication failed!"; } $ssh2->scp_get('/home/jansen/_SCP_'); exit 0; -- / snip -- |