Thread: [Ssh-sftp-perl-users] How to load my private DSA key for authentication?
Brought to you by:
dbrobins
From: Anthony L. <ant...@ya...> - 2012-02-08 21:49:05
|
Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? $host = "my.server.com"; $user = "myusername"; $pk = "private.key"; $port = 22; $sftp = Net::SSH::Perl->new (?????); # What constructor do I use? Any hint? Thank you. If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? |
From: Anthony L. <ant...@ya...> - 2012-02-09 16:39:38
|
Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. use Net::SFTP::Foreign; $host = "my.sftp.server.com"; $port = 22; $user = "myusername"; $keypath = "c:/path/to/private.key"; $ssh = "c:/path/to/putty.exe"; my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); if ($sftp->error) { print "sftp error: ". $sftp ->error."\n"; } I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. ________________________________ From: Russ Brewer <us...@gm...> To: Anthony Liu <ant...@ya...> Sent: Wednesday, February 8, 2012 5:24 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; if ($@) { print "Failed SSH Connection to $remote_server\n"; print "$@\n"; } else { print " Successful SSH connection to $remote_server\n"; } ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and ## script is being run by $user ## $ssh->login($user, $password) eval {$ssh->login()}; if ($@) { print "Failed Login on Server $remote_server\n"; print "$@"; } else { print " Successful SSH login to $remote_server\n"; } Test your key pairs manually from the command line to be sure they are set up correctly. But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? > > >$host = "my.server.com"; >$user = "myusername"; >$pk = "private.key"; >$port = 22; > > >$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? > > >Any hint? Thank you. > > >If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >------------------------------------------------------------------------------ >Keep Your Developer Skills Current with LearnDevNow! >The most comprehensive online learning library for Microsoft developers >is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >Metro Style Apps, more. Free future releases when you subscribe now! >http://p.sf.net/sfu/learndevnow-d2d >_______________________________________________ >Ssh-sftp-perl-users mailing list >Ssh...@li... >https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > |
From: Anthony L. <ant...@ya...> - 2012-02-09 22:12:24
|
OK, thanks. I am testing Net::SSH2. I run sshd on my ubuntu box. I logged into my ubuntu as aliu, generated a pair of dsa keys through ssh-keygen -t dsa I transferred the key pair files to my windows box and run this: use Net::SSH2; $host = "my.server.com"; $port = 22; $user = "aliu"; $publickey="id_dsa.pub"; $privatekey = "id_dsa"; my $sftp = Net::SSH2->new(); $sftp->connect($host, $port) or die $!; $sftp->auth_publickey($user, $publickey, $privatekey); if ($sftp->error) { my ( $code, $error_name, $error_message ) = $sftp->error; print "sftp error[$code] $error_name: $error_message \n"; } else { print "Hooray!"; } The error message says: sftp error[-18] LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: Username/PublicKey combina tion invalid Note that I have no problem ssh-ing to my ubuntu sshd instance through WinSCP using user name aliu and my password. ________________________________ From: Russ Brewer <us...@gm...> To: Anthony Liu <ant...@ya...> Sent: Thursday, February 9, 2012 1:12 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? The following works for a Net::SFTP::Foreign connection. I use a Linux system not Windows so I am not sure what difference that might make. But I see this in the documentation at the CPAN site: "Note that password authentication on Windows OSs only works when the Cygwin port of Perl is used." Do you meet that requirement? On my Linux system I use the following code: # the '-v' arg sets ssh debug mode # our @sshargs = ('-v'); my $hostname = 'hostname' my $ssh_cmd = "/usr/bin/ssh" my $user = 'user' my $password = 'password'; # or passphrase my $pki_no_passphrase = 'yes'; # or no if using a password or a passphrase our $sftp; our @ssh_options; if ( $pki_no_passphrase =~ /^yes$/i ) { # using pki keys with no passphrase protection @ssh_options = ('-oPreferredAuthentications=publickey'); $sftp = Net::SFTP::Foreign->new( host => $hostname, user => $user, ssh_cmd => $ssh_cmd, more => [@ssh_options] ); } else { # password (or passphrase protected pki key) is in use @ssh_options = ('-oPreferredAuthentications=publickey,password'); $sftp = Net::SFTP::Foreign->new( host => $hostname, user => $user, password => $password, expect_log_user => 1, ssh_cmd => $ssh_cmd, more => [@ssh_options] ); } You must have the Expect.pm module to use a password or a non-empty PKI passphrase. You must use the 'expect_log_user' item when using a password or a non-empty passphrase. If you are using an empty PKI passphrase you do not use the 'password' or 'expect_log_user' items. This is the easiest way to do it and you don't have to store the password or passphrase in your script. On Thu, Feb 9, 2012 at 11:39 AM, Anthony Liu <ant...@ya...> wrote: Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. > > >use Net::SFTP::Foreign; > > >$host = "my.sftp.server.com"; >$port = 22; >$user = "myusername"; >$keypath = "c:/path/to/private.key"; >$ssh = "c:/path/to/putty.exe"; > > >my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); > > >if ($sftp->error) >{ > print "sftp error: ". $sftp ->error."\n"; >} > > >I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". > > >I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. > > > >________________________________ > From: Russ Brewer <us...@gm...> >To: Anthony Liu <ant...@ya...> >Sent: Wednesday, February 8, 2012 5:24 PM >Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? > > > >Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. > > eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; > > if ($@) { > print "Failed SSH Connection to $remote_server\n"; > print "$@\n"; > } else { > print " Successful SSH connection to $remote_server\n"; > } > > ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and > ## script is being run by $user > > ## $ssh->login($user, $password) > > eval {$ssh->login()}; > if ($@) { > print "Failed Login on Server $remote_server\n"; > print "$@"; > } else { > print " Successful SSH login to $remote_server\n"; > } > >Test your key pairs manually from the command line to be sure they are set up correctly. >But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) > > >On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: > >Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? >> >> >>$host = "my.server.com"; >>$user = "myusername"; >>$pk = "private.key"; >>$port = 22; >> >> >>$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? >> >> >>Any hint? Thank you. >> >> >>If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >>------------------------------------------------------------------------------ >>Keep Your Developer Skills Current with LearnDevNow! >>The most comprehensive online learning library for Microsoft developers >>is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>Metro Style Apps, more. Free future releases when you subscribe now! >>http://p.sf.net/sfu/learndevnow-d2d >>_______________________________________________ >>Ssh-sftp-perl-users mailing list >>Ssh...@li... >>https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >> >> > > > |
From: Anthony L. <ant...@ya...> - 2012-02-10 03:50:55
|
Thank you. I don't remember if there is a authorized_keys file there, but I'll check first thing tomorrow morning. That might be the problem. ________________________________ From: Russ Brewer <us...@gm...> To: Anthony Liu <ant...@ya...> Sent: Thursday, February 9, 2012 5:48 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? Anthony, Is the host target you are connecting to your ubuntu server? If so, are you sure you have the public key correctly installed on the target server? Typically, this would be in the .ssh directory in the home directory for user aliu, for example: /home/aliu/.ssh (with directory permission 600) Within the .ssh directory should be a file named 'authorized_keys' which must hold a copy of the public key you created. If this file is not present, create it and then append the public portion of the key pair into it. When you sftp to the ubuntu server as user aliu, the system uses the /home/aliu/.ssh/authorized_keys file to verify and validate the person attempting the login. The key pair being used for authentication is the private half on the Windows server and the public half as installed in the authorized_keys file on the destination server. I apologize if I am addressing issues you are sure are not the issue. But in my experience the single largest reason for not being able to automate a Perl based ssh or sftp connection is that the keys pairs are not properly installed with correct permissions. Russ On Thu, Feb 9, 2012 at 5:12 PM, Anthony Liu <ant...@ya...> wrote: OK, thanks. I am testing Net::SSH2. > > >I run sshd on my ubuntu box. I logged into my ubuntu as aliu, generated a pair of dsa keys through ssh-keygen -t dsa > > >I transferred the key pair files to my windows box and run this: > > >use Net::SSH2; > > >$host = "my.server.com"; >$port = 22; >$user = "aliu"; >$publickey="id_dsa.pub"; >$privatekey = "id_dsa"; > > >my $sftp = Net::SSH2->new(); >$sftp->connect($host, $port) or die $!; > > >$sftp->auth_publickey($user, $publickey, $privatekey); > > >if ($sftp->error) >{ > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; > > >} >else >{ > print "Hooray!"; >} > > >The error message says: > > >sftp error[-18] LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: Username/PublicKey combina >tion invalid > > >Note that I have no problem ssh-ing to my ubuntu sshd instance through WinSCP using user name aliu and my password. > > > >________________________________ > From: Russ Brewer <us...@gm...> >To: Anthony Liu <ant...@ya...> >Sent: Thursday, February 9, 2012 1:12 PM > >Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? > > > >The following works for a Net::SFTP::Foreign connection. > I use a Linux system not Windows so I am not sure what difference that might make. But I see this in the documentation at the CPAN site: > >"Note that password authentication on Windows OSs only works when the Cygwin port of Perl is used." > >Do you meet that requirement? > >On my Linux system I use the following code: > > # the '-v' arg sets ssh debug mode > # our @sshargs = ('-v'); > > my $hostname = 'hostname' > my $ssh_cmd = "/usr/bin/ssh" > my $user = 'user' > my $password = 'password'; # or passphrase > my $pki_no_passphrase = 'yes'; # or no if using a password or a passphrase > > our $sftp; > our @ssh_options; > if ( $pki_no_passphrase =~ /^yes$/i ) { > # using pki keys with no passphrase protection > @ssh_options = ('-oPreferredAuthentications=publickey'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } else { > # password (or passphrase protected pki key) is in use > @ssh_options = ('-oPreferredAuthentications=publickey,password'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > password => $password, > expect_log_user => 1, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } > >You must have the Expect.pm module to use a password or a non-empty PKI passphrase. You must use the 'expect_log_user' item when using a password or a non-empty passphrase. > >If you are using an empty PKI passphrase you do not use the 'password' or 'expect_log_user' items. This is the easiest way to do it and you don't have to store the password or passphrase in your script. > > >On Thu, Feb 9, 2012 at 11:39 AM, Anthony Liu <ant...@ya...> wrote: > >Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. >> >> >>use Net::SFTP::Foreign; >> >> >>$host = "my.sftp.server.com"; >>$port = 22; >>$user = "myusername"; >>$keypath = "c:/path/to/private.key"; >>$ssh = "c:/path/to/putty.exe"; >> >> >>my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); >> >> >>if ($sftp->error) >>{ >> print "sftp error: ". $sftp ->error."\n"; >>} >> >> >>I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". >> >> >>I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. >> >> >> >>________________________________ >> From: Russ Brewer <us...@gm...> >>To: Anthony Liu <ant...@ya...> >>Sent: Wednesday, February 8, 2012 5:24 PM >>Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? >> >> >> >>Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. >> >> eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; >> >> if ($@) { >> print "Failed SSH Connection to $remote_server\n"; >> print "$@\n"; >> } else { >> print " Successful SSH connection to $remote_server\n"; >> } >> >> ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and >> ## script is being run by $user >> >> ## $ssh->login($user, $password) >> >> eval {$ssh->login()}; >> if ($@) { >> print "Failed Login on Server $remote_server\n"; >> print "$@"; >> } else { >> print " Successful SSH login to $remote_server\n"; >> } >> >>Test your key pairs manually from the command line to be sure they are set up correctly. >>But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) >> >> >>On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: >> >>Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? >>> >>> >>>$host = "my.server.com"; >>>$user = "myusername"; >>>$pk = "private.key"; >>>$port = 22; >>> >>> >>>$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? >>> >>> >>>Any hint? Thank you. >>> >>> >>>If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >>>------------------------------------------------------------------------------ >>>Keep Your Developer Skills Current with LearnDevNow! >>>The most comprehensive online learning library for Microsoft developers >>>is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>>Metro Style Apps, more. Free future releases when you subscribe now! >>>http://p.sf.net/sfu/learndevnow-d2d >>>_______________________________________________ >>>Ssh-sftp-perl-users mailing list >>>Ssh...@li... >>>https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >>> >>> >> >> >> > > > |
From: Anthony L. <ant...@ya...> - 2012-02-10 16:01:46
|
Thank you for your continued support. I followed the instructions at http://www.csse.uwa.edu.au/~ryan/tech/ssh-no-password.html and created authorized_keys2 which contains the public key. In my case, it is exactly the same as id_dsa.pub. See below: aliu@aliu-VirtualBox:~/.ssh$ ls -l total 16 -rw------- 1 aliu aliu 612 2012-02-10 09:52 authorized_keys2 -rw------- 1 aliu aliu 668 2012-02-09 16:01 id_dsa -rw-r--r-- 1 aliu aliu 612 2012-02-09 16:01 id_dsa.pub -rw-r--r-- 1 aliu aliu 222 2012-02-09 14:36 known_hosts aliu@aliu-VirtualBox:~/.ssh$ When I run the code I pasted yesterday, I get an error which says: sftp error[-37] LIBSSH2_ERROR_EAGAIN: Would block requesting userauth list I have no idea what this error means and how to go about it fixing it. I do have id_dsa and id_dsa.pub in the same folder as my perl script on my windows 7 box. ________________________________ From: Russ Brewer <us...@gm...> To: Anthony Liu <ant...@ya...> Sent: Thursday, February 9, 2012 5:48 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? Anthony, Is the host target you are connecting to your ubuntu server? If so, are you sure you have the public key correctly installed on the target server? Typically, this would be in the .ssh directory in the home directory for user aliu, for example: /home/aliu/.ssh (with directory permission 600) Within the .ssh directory should be a file named 'authorized_keys' which must hold a copy of the public key you created. If this file is not present, create it and then append the public portion of the key pair into it. When you sftp to the ubuntu server as user aliu, the system uses the /home/aliu/.ssh/authorized_keys file to verify and validate the person attempting the login. The key pair being used for authentication is the private half on the Windows server and the public half as installed in the authorized_keys file on the destination server. I apologize if I am addressing issues you are sure are not the issue. But in my experience the single largest reason for not being able to automate a Perl based ssh or sftp connection is that the keys pairs are not properly installed with correct permissions. Russ On Thu, Feb 9, 2012 at 5:12 PM, Anthony Liu <ant...@ya...> wrote: OK, thanks. I am testing Net::SSH2. > > >I run sshd on my ubuntu box. I logged into my ubuntu as aliu, generated a pair of dsa keys through ssh-keygen -t dsa > > >I transferred the key pair files to my windows box and run this: > > >use Net::SSH2; > > >$host = "my.server.com"; >$port = 22; >$user = "aliu"; >$publickey="id_dsa.pub"; >$privatekey = "id_dsa"; > > >my $sftp = Net::SSH2->new(); >$sftp->connect($host, $port) or die $!; > > >$sftp->auth_publickey($user, $publickey, $privatekey); > > >if ($sftp->error) >{ > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; > > >} >else >{ > print "Hooray!"; >} > > >The error message says: > > >sftp error[-18] LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: Username/PublicKey combina >tion invalid > > >Note that I have no problem ssh-ing to my ubuntu sshd instance through WinSCP using user name aliu and my password. > > > >________________________________ > From: Russ Brewer <us...@gm...> >To: Anthony Liu <ant...@ya...> >Sent: Thursday, February 9, 2012 1:12 PM > >Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? > > > >The following works for a Net::SFTP::Foreign connection. > I use a Linux system not Windows so I am not sure what difference that might make. But I see this in the documentation at the CPAN site: > >"Note that password authentication on Windows OSs only works when the Cygwin port of Perl is used." > >Do you meet that requirement? > >On my Linux system I use the following code: > > # the '-v' arg sets ssh debug mode > # our @sshargs = ('-v'); > > my $hostname = 'hostname' > my $ssh_cmd = "/usr/bin/ssh" > my $user = 'user' > my $password = 'password'; # or passphrase > my $pki_no_passphrase = 'yes'; # or no if using a password or a passphrase > > our $sftp; > our @ssh_options; > if ( $pki_no_passphrase =~ /^yes$/i ) { > # using pki keys with no passphrase protection > @ssh_options = ('-oPreferredAuthentications=publickey'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } else { > # password (or passphrase protected pki key) is in use > @ssh_options = ('-oPreferredAuthentications=publickey,password'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > password => $password, > expect_log_user => 1, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } > >You must have the Expect.pm module to use a password or a non-empty PKI passphrase. You must use the 'expect_log_user' item when using a password or a non-empty passphrase. > >If you are using an empty PKI passphrase you do not use the 'password' or 'expect_log_user' items. This is the easiest way to do it and you don't have to store the password or passphrase in your script. > > >On Thu, Feb 9, 2012 at 11:39 AM, Anthony Liu <ant...@ya...> wrote: > >Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. >> >> >>use Net::SFTP::Foreign; >> >> >>$host = "my.sftp.server.com"; >>$port = 22; >>$user = "myusername"; >>$keypath = "c:/path/to/private.key"; >>$ssh = "c:/path/to/putty.exe"; >> >> >>my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); >> >> >>if ($sftp->error) >>{ >> print "sftp error: ". $sftp ->error."\n"; >>} >> >> >>I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". >> >> >>I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. >> >> >> >>________________________________ >> From: Russ Brewer <us...@gm...> >>To: Anthony Liu <ant...@ya...> >>Sent: Wednesday, February 8, 2012 5:24 PM >>Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? >> >> >> >>Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. >> >> eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; >> >> if ($@) { >> print "Failed SSH Connection to $remote_server\n"; >> print "$@\n"; >> } else { >> print " Successful SSH connection to $remote_server\n"; >> } >> >> ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and >> ## script is being run by $user >> >> ## $ssh->login($user, $password) >> >> eval {$ssh->login()}; >> if ($@) { >> print "Failed Login on Server $remote_server\n"; >> print "$@"; >> } else { >> print " Successful SSH login to $remote_server\n"; >> } >> >>Test your key pairs manually from the command line to be sure they are set up correctly. >>But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) >> >> >>On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: >> >>Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? >>> >>> >>>$host = "my.server.com"; >>>$user = "myusername"; >>>$pk = "private.key"; >>>$port = 22; >>> >>> >>>$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? >>> >>> >>>Any hint? Thank you. >>> >>> >>>If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >>>------------------------------------------------------------------------------ >>>Keep Your Developer Skills Current with LearnDevNow! >>>The most comprehensive online learning library for Microsoft developers >>>is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>>Metro Style Apps, more. Free future releases when you subscribe now! >>>http://p.sf.net/sfu/learndevnow-d2d >>>_______________________________________________ >>>Ssh-sftp-perl-users mailing list >>>Ssh...@li... >>>https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >>> >>> >> >> >> > > > |
From: Anthony L. <ant...@ya...> - 2012-02-10 19:18:23
|
I am starting to suspect that Net::SSH2 methods do not work on Windows because if I run the same perl script on my Ubuntu box, it works perfectly and does not generate an error. But on Windows 7, I keep on getting this obscure "sftp error[-37] LIBSSH2_ERROR_EAGAIN: Would block requesting userauth list" error. ________________________________ From: Russ Brewer <us...@gm...> To: ant...@ya... Sent: Thursday, February 9, 2012 5:49 PM Subject: Fwd: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? Sorry, the directory permission on the .ssh directory should be 700 not 600. ---------- Forwarded message ---------- From: Russ Brewer <us...@gm...> Date: Thu, Feb 9, 2012 at 5:48 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? To: Anthony Liu <ant...@ya...> Anthony, Is the host target you are connecting to your ubuntu server? If so, are you sure you have the public key correctly installed on the target server? Typically, this would be in the .ssh directory in the home directory for user aliu, for example: /home/aliu/.ssh (with directory permission 600) Within the .ssh directory should be a file named 'authorized_keys' which must hold a copy of the public key you created. If this file is not present, create it and then append the public portion of the key pair into it. When you sftp to the ubuntu server as user aliu, the system uses the /home/aliu/.ssh/authorized_keys file to verify and validate the person attempting the login. The key pair being used for authentication is the private half on the Windows server and the public half as installed in the authorized_keys file on the destination server. I apologize if I am addressing issues you are sure are not the issue. But in my experience the single largest reason for not being able to automate a Perl based ssh or sftp connection is that the keys pairs are not properly installed with correct permissions. Russ On Thu, Feb 9, 2012 at 5:12 PM, Anthony Liu <ant...@ya...> wrote: OK, thanks. I am testing Net::SSH2. > > >I run sshd on my ubuntu box. I logged into my ubuntu as aliu, generated a pair of dsa keys through ssh-keygen -t dsa > > >I transferred the key pair files to my windows box and run this: > > >use Net::SSH2; > > >$host = "my.server.com"; >$port = 22; >$user = "aliu"; >$publickey="id_dsa.pub"; >$privatekey = "id_dsa"; > > >my $sftp = Net::SSH2->new(); >$sftp->connect($host, $port) or die $!; > > >$sftp->auth_publickey($user, $publickey, $privatekey); > > >if ($sftp->error) >{ > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; > > >} >else >{ > print "Hooray!"; >} > > >The error message says: > > >sftp error[-18] LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: Username/PublicKey combina >tion invalid > > >Note that I have no problem ssh-ing to my ubuntu sshd instance through WinSCP using user name aliu and my password. > > > >________________________________ > From: Russ Brewer <us...@gm...> >To: Anthony Liu <ant...@ya...> >Sent: Thursday, February 9, 2012 1:12 PM > >Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? > > > >The following works for a Net::SFTP::Foreign connection. > I use a Linux system not Windows so I am not sure what difference that might make. But I see this in the documentation at the CPAN site: > >"Note that password authentication on Windows OSs only works when the Cygwin port of Perl is used." > >Do you meet that requirement? > >On my Linux system I use the following code: > > # the '-v' arg sets ssh debug mode > # our @sshargs = ('-v'); > > my $hostname = 'hostname' > my $ssh_cmd = "/usr/bin/ssh" > my $user = 'user' > my $password = 'password'; # or passphrase > my $pki_no_passphrase = 'yes'; # or no if using a password or a passphrase > > our $sftp; > our @ssh_options; > if ( $pki_no_passphrase =~ /^yes$/i ) { > # using pki keys with no passphrase protection > @ssh_options = ('-oPreferredAuthentications=publickey'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } else { > # password (or passphrase protected pki key) is in use > @ssh_options = ('-oPreferredAuthentications=publickey,password'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > password => $password, > expect_log_user => 1, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } > >You must have the Expect.pm module to use a password or a non-empty PKI passphrase. You must use the 'expect_log_user' item when using a password or a non-empty passphrase. > >If you are using an empty PKI passphrase you do not use the 'password' or 'expect_log_user' items. This is the easiest way to do it and you don't have to store the password or passphrase in your script. > > >On Thu, Feb 9, 2012 at 11:39 AM, Anthony Liu <ant...@ya...> wrote: > >Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. >> >> >>use Net::SFTP::Foreign; >> >> >>$host = "my.sftp.server.com"; >>$port = 22; >>$user = "myusername"; >>$keypath = "c:/path/to/private.key"; >>$ssh = "c:/path/to/putty.exe"; >> >> >>my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); >> >> >>if ($sftp->error) >>{ >> print "sftp error: ". $sftp ->error."\n"; >>} >> >> >>I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". >> >> >>I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. >> >> >> >>________________________________ >> From: Russ Brewer <us...@gm...> >>To: Anthony Liu <ant...@ya...> >>Sent: Wednesday, February 8, 2012 5:24 PM >>Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? >> >> >> >>Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. >> >> eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; >> >> if ($@) { >> print "Failed SSH Connection to $remote_server\n"; >> print "$@\n"; >> } else { >> print " Successful SSH connection to $remote_server\n"; >> } >> >> ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and >> ## script is being run by $user >> >> ## $ssh->login($user, $password) >> >> eval {$ssh->login()}; >> if ($@) { >> print "Failed Login on Server $remote_server\n"; >> print "$@"; >> } else { >> print " Successful SSH login to $remote_server\n"; >> } >> >>Test your key pairs manually from the command line to be sure they are set up correctly. >>But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) >> >> >>On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: >> >>Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? >>> >>> >>>$host = "my.server.com"; >>>$user = "myusername"; >>>$pk = "private.key"; >>>$port = 22; >>> >>> >>>$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? >>> >>> >>>Any hint? Thank you. >>> >>> >>>If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >>>------------------------------------------------------------------------------ >>>Keep Your Developer Skills Current with LearnDevNow! >>>The most comprehensive online learning library for Microsoft developers >>>is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>>Metro Style Apps, more. Free future releases when you subscribe now! >>>http://p.sf.net/sfu/learndevnow-d2d >>>_______________________________________________ >>>Ssh-sftp-perl-users mailing list >>>Ssh...@li... >>>https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >>> >>> >> >> >> > > > |
From: Anthony L. <ant...@ya...> - 2012-02-10 19:48:08
|
Does anyone out there have a minimum working example using Net::SFTP::Foreign with plink.exe? I tried this: use Net::SFTP::Foreign; $host = "my.ssh.server.com"; $port = 22; $user = "aliu"; $publickey="id_dsa.pub"; $privatekey = "id_dsa"; $sshcmd = "plink.exe"; %args = ("port", $port, "key_path", $privatekey, "user", $user, "ssh_cmd", $sshcmd); my $sftp = Net::SFTP::Foreign->new(host=>@host, %args); if ($sftp->error) { my ( $code, $error_name, $error_message ) = $sftp->error; print "sftp error[$code] $error_name: $error_message \n"; } else { print "Success!"; } But I get an error saying: Invalid option 'key_path' or bad combination of options at ./test.pl line 14 The documentation doesn't tell me what combinations are acceptable, and online sources are so limited, I am basically clueless. ________________________________ From: Russ Brewer <us...@gm...> To: ant...@ya... Sent: Thursday, February 9, 2012 5:49 PM Subject: Fwd: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? Sorry, the directory permission on the .ssh directory should be 700 not 600. ---------- Forwarded message ---------- From: Russ Brewer <us...@gm...> Date: Thu, Feb 9, 2012 at 5:48 PM Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? To: Anthony Liu <ant...@ya...> Anthony, Is the host target you are connecting to your ubuntu server? If so, are you sure you have the public key correctly installed on the target server? Typically, this would be in the .ssh directory in the home directory for user aliu, for example: /home/aliu/.ssh (with directory permission 600) Within the .ssh directory should be a file named 'authorized_keys' which must hold a copy of the public key you created. If this file is not present, create it and then append the public portion of the key pair into it. When you sftp to the ubuntu server as user aliu, the system uses the /home/aliu/.ssh/authorized_keys file to verify and validate the person attempting the login. The key pair being used for authentication is the private half on the Windows server and the public half as installed in the authorized_keys file on the destination server. I apologize if I am addressing issues you are sure are not the issue. But in my experience the single largest reason for not being able to automate a Perl based ssh or sftp connection is that the keys pairs are not properly installed with correct permissions. Russ On Thu, Feb 9, 2012 at 5:12 PM, Anthony Liu <ant...@ya...> wrote: OK, thanks. I am testing Net::SSH2. > > >I run sshd on my ubuntu box. I logged into my ubuntu as aliu, generated a pair of dsa keys through ssh-keygen -t dsa > > >I transferred the key pair files to my windows box and run this: > > >use Net::SSH2; > > >$host = "my.server.com"; >$port = 22; >$user = "aliu"; >$publickey="id_dsa.pub"; >$privatekey = "id_dsa"; > > >my $sftp = Net::SSH2->new(); >$sftp->connect($host, $port) or die $!; > > >$sftp->auth_publickey($user, $publickey, $privatekey); > > >if ($sftp->error) >{ > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; > > >} >else >{ > print "Hooray!"; >} > > >The error message says: > > >sftp error[-18] LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: Username/PublicKey combina >tion invalid > > >Note that I have no problem ssh-ing to my ubuntu sshd instance through WinSCP using user name aliu and my password. > > > >________________________________ > From: Russ Brewer <us...@gm...> >To: Anthony Liu <ant...@ya...> >Sent: Thursday, February 9, 2012 1:12 PM > >Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? > > > >The following works for a Net::SFTP::Foreign connection. > I use a Linux system not Windows so I am not sure what difference that might make. But I see this in the documentation at the CPAN site: > >"Note that password authentication on Windows OSs only works when the Cygwin port of Perl is used." > >Do you meet that requirement? > >On my Linux system I use the following code: > > # the '-v' arg sets ssh debug mode > # our @sshargs = ('-v'); > > my $hostname = 'hostname' > my $ssh_cmd = "/usr/bin/ssh" > my $user = 'user' > my $password = 'password'; # or passphrase > my $pki_no_passphrase = 'yes'; # or no if using a password or a passphrase > > our $sftp; > our @ssh_options; > if ( $pki_no_passphrase =~ /^yes$/i ) { > # using pki keys with no passphrase protection > @ssh_options = ('-oPreferredAuthentications=publickey'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } else { > # password (or passphrase protected pki key) is in use > @ssh_options = ('-oPreferredAuthentications=publickey,password'); > $sftp = Net::SFTP::Foreign->new( > host => $hostname, > user => $user, > password => $password, > expect_log_user => 1, > ssh_cmd => $ssh_cmd, > more => [@ssh_options] > ); > } > >You must have the Expect.pm module to use a password or a non-empty PKI passphrase. You must use the 'expect_log_user' item when using a password or a non-empty passphrase. > >If you are using an empty PKI passphrase you do not use the 'password' or 'expect_log_user' items. This is the easiest way to do it and you don't have to store the password or passphrase in your script. > > >On Thu, Feb 9, 2012 at 11:39 AM, Anthony Liu <ant...@ya...> wrote: > >Thank you for your hint. Yes, I am really after sftp, and I did try Net::SFTP::Foreign. But I can't seem to succeed. Problem is I can't figure out what combination of parameters I should use in the constructor. >> >> >>use Net::SFTP::Foreign; >> >> >>$host = "my.sftp.server.com"; >>$port = 22; >>$user = "myusername"; >>$keypath = "c:/path/to/private.key"; >>$ssh = "c:/path/to/putty.exe"; >> >> >>my $sftp = Net::SFTP::Foreign-> new(host=>$host, port=>$port, user=>$user, ssh_cmd=>$ssh, key_path=>$keypath); >> >> >>if ($sftp->error) >>{ >> print "sftp error: ". $sftp ->error."\n"; >>} >> >> >>I get an error running this, which says "Invalid option 'key_path' or bad combination of options at ..". >> >> >>I have to use the given user name and the given private key file to get authenticated by the remote SFTP server. >> >> >> >>________________________________ >> From: Russ Brewer <us...@gm...> >>To: Anthony Liu <ant...@ya...> >>Sent: Wednesday, February 8, 2012 5:24 PM >>Subject: Re: [Ssh-sftp-perl-users] How to load my private DSA key for authentication? >> >> >> >>Net::SSH::Perl supports PKI keys. This is how I do it -- and how I error check it. >> >> eval {$ssh = Net::SSH::Perl->new($remote_server, debug=>0)}; >> >> if ($@) { >> print "Failed SSH Connection to $remote_server\n"; >> print "$@\n"; >> } else { >> print " Successful SSH connection to $remote_server\n"; >> } >> >> ## Don't need to $user or $password if PKI key pairs are set up, working correctly, and >> ## script is being run by $user >> >> ## $ssh->login($user, $password) >> >> eval {$ssh->login()}; >> if ($@) { >> print "Failed Login on Server $remote_server\n"; >> print "$@"; >> } else { >> print " Successful SSH login to $remote_server\n"; >> } >> >>Test your key pairs manually from the command line to be sure they are set up correctly. >>But if what you are really after is a Net::SFTP file transfer, I recommend Net::SFTP::Foreign instead of Net::SFTP (which is build on Net::SSH::Perl) >> >> >>On Wed, Feb 8, 2012 at 4:48 PM, Anthony Liu <ant...@ya...> wrote: >> >>Hi, I am wondering if anyone of you could give me a hint. Using Net::SSH::Perl, how do I authenticate myself through my user name and my DSA private key? >>> >>> >>>$host = "my.server.com"; >>>$user = "myusername"; >>>$pk = "private.key"; >>>$port = 22; >>> >>> >>>$sftp = Net::SSH::Perl->new (?????); # What constructor do I use? >>> >>> >>>Any hint? Thank you. >>> >>> >>>If Net::SSH::Perl doesn't support public/private key authentication, what other module can I use? Any minimum working example? >>>------------------------------------------------------------------------------ >>>Keep Your Developer Skills Current with LearnDevNow! >>>The most comprehensive online learning library for Microsoft developers >>>is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>>Metro Style Apps, more. Free future releases when you subscribe now! >>>http://p.sf.net/sfu/learndevnow-d2d >>>_______________________________________________ >>>Ssh-sftp-perl-users mailing list >>>Ssh...@li... >>>https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >>> >>> >> >> >> > > > |
From: Anthony L. <ant...@ya...> - 2012-02-13 14:50:55
|
Thanks for spotting that typo, but fixing that typo does not fix the problem. The exactly same problem remains: Invalid option 'key_path' or bad combination of options at ./test.pl line 14 I have this version: Net-SFTP-Foreign-1.69 from http://search.cpan.org/~salva/Net-SFTP-Foreign-1.69/lib/Net/SFTP/Foreign.pm And my perl is Strawberry Perl 5, version 12. I am not sure why the documentation doesn't say what combinations are accepted and what are not. I think my combination makes sense: I do need to specify the port number, I do need to specify the private key file path, I do need to specify the user name, I do need to specify the ssh command. ________________________________ From: Salvador Fandino <sfa...@ya...> To: Anthony Liu <ant...@ya...> Sent: Monday, February 13, 2012 4:21 AM Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? >________________________________ > From: Anthony Liu <ant...@ya...> >To: Russ Brewer <us...@gm...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Friday, February 10, 2012 8:48 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Does anyone out there have a minimum working example using Net::SFTP::Foreign with plink.exe? I tried this: > > >use Net::SFTP::Foreign; > >$host = "my.ssh.server.com"; >$port = 22; >$user = "aliu"; >$publickey="id_dsa.pub"; >$privatekey = "id_dsa"; >$sshcmd = "plink.exe"; > >%args = ("port", $port, "key_path", $privatekey, "user", $user, "ssh_cmd", $sshcmd); > >my $sftp = Net::SFTP::Foreign->new(host=>@host, %args); > >if ($sftp->error) >{ > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; >} >else >{ > print "Success!"; >} > >But I get an error saying: Invalid option 'key_path' or bad combination of options at ./test.pl line 14 You are defining $host but passing @host. Activate warnings and strict on you programs. Which version of Net::SFTP::Foreign have you installed. To known, run the following command: perl -MNet::SFTP::Foreign -e 'print qq($Net::SFTP::Foreign::VERSION\n)' |
From: Salvador F. <sfa...@ya...> - 2012-02-13 15:51:38
|
>________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 3:50 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Thanks for spotting that typo, but fixing that typo does not fix the problem. The exactly same problem remains: > > >Invalid option 'key_path' or bad combination of options at ./test.pl line 14 > > > >I have this version: Net-SFTP-Foreign-1.69 from http://search.cpan.org/~salva/Net-SFTP-Foreign-1.69/lib/Net/SFTP/Foreign.pm > > >And my perl is Strawberry Perl 5, version 12. I am not sure why the documentation doesn't say what combinations are accepted and what are not. I think my combination makes sense: > > >I do need to specify the port number, >I do need to specify the private key file path, >I do need to specify the user name, >I do need to specify the ssh command. That combination is supported, and it works for me: Y:\t\Net-SFTP-Foreign-1.69>type Y:\g\perl\p5-Net-SFTP-Foreign\samples\key_path.pl use strict; use warnings; use Net::SFTP::Foreign; print "This is Net::SFTP::Foreign $Net::SFTP::Foreign::VERSION running on perl $^V on $^O\n"; my $sftp = Net::SFTP::Foreign->new('10.0.2.2', key_path => 'Y:/.ssh/id_dsa_plink.ppk', port => 22, user => 'salva', ssh_cmd => 'C:/Archivos de Programa/PuTTY/plink.exe'); $sftp->error and die $sftp->error; my @g = $sftp->glob('/etc/pass*', names_only => 1); print "$_\n" for @g; Y:\t\Net-SFTP-Foreign-1.69>perl -Ilib Y:\g\perl\p5-Net-SFTP-Foreign\samples\key_path.pl This is Net::SFTP::Foreign 1.69 running on perl v5.12.3 on MSWin32 /etc/passwd /etc/passwd- Are you sure you don't have another version of Net::SFTP::Foreign installed that is being picked by perl instead of 1.69? Otherwise, try the latest development version of the module (1.70_06), add the following line to the beginning of your script: $Net::SFTP::Foreign::debug = ~0; Rerun it and send me the output. Include also its full, unmodified source code. |
From: Anthony L. <ant...@ya...> - 2012-02-13 16:03:17
|
Well, you are right, I adapted your script, ran it and I got this: This is Net::SFTP::Foreign 1.57 running on perl v5.12.3 on MSWin32 Now, before I make other tests, how can I have Perl pick up my Net::SFTP:Foreign 1.69? ________________________________ From: Salvador Fandino <sfa...@ya...> To: Anthony Liu <ant...@ya...> Cc: "Ssh...@li..." <Ssh...@li...> Sent: Monday, February 13, 2012 10:48 AM Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? >________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 3:50 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Thanks for spotting that typo, but fixing that typo does not fix the problem. The exactly same problem remains: > > >Invalid option 'key_path' or bad combination of options at ./test.pl line 14 > > > >I have this version: Net-SFTP-Foreign-1.69 from http://search.cpan.org/~salva/Net-SFTP-Foreign-1.69/lib/Net/SFTP/Foreign.pm > > >And my perl is Strawberry Perl 5, version 12. I am not sure why the documentation doesn't say what combinations are accepted and what are not. I think my combination makes sense: > > >I do need to specify the port number, >I do need to specify the private key file path, >I do need to specify the user name, >I do need to specify the ssh command. That combination is supported, and it works for me: Y:\t\Net-SFTP-Foreign-1.69>type Y:\g\perl\p5-Net-SFTP-Foreign\samples\key_path.pl use strict; use warnings; use Net::SFTP::Foreign; print "This is Net::SFTP::Foreign $Net::SFTP::Foreign::VERSION running on perl $^V on $^O\n"; my $sftp = Net::SFTP::Foreign->new('10.0.2.2', key_path => 'Y:/.ssh/id_dsa_plink.ppk', port => 22, user => 'salva', ssh_cmd => 'C:/Archivos de Programa/PuTTY/plink.exe'); $sftp->error and die $sftp->error; my @g = $sftp->glob('/etc/pass*', names_only => 1); print "$_\n" for @g; Y:\t\Net-SFTP-Foreign-1.69>perl -Ilib Y:\g\perl\p5-Net-SFTP-Foreign\samples\key_path.pl This is Net::SFTP::Foreign 1.69 running on perl v5.12.3 on MSWin32 /etc/passwd /etc/passwd- Are you sure you don't have another version of Net::SFTP::Foreign installed that is being picked by perl instead of 1.69? Otherwise, try the latest development version of the module (1.70_06), add the following line to the beginning of your script: $Net::SFTP::Foreign::debug = ~0; Rerun it and send me the output. Include also its full, unmodified source code. |
From: Salvador F. <sfa...@ya...> - 2012-02-13 16:31:45
|
>________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 5:03 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Well, you are right, I adapted your script, ran it and I got this: > > >This is Net::SFTP::Foreign 1.57 running on perl v5.12.3 on MSWin32 > > > >Now, before I make other tests, how can I have Perl pick up my Net::SFTP:Foreign 1.69? Delete the files from the old version from your hard disk. Add the following lines to your script, to see find it: use Net::SFTP::Foreign; use Data::Dumper; print Dump \%INC; |
From: Anthony L. <ant...@ya...> - 2012-02-13 16:44:06
|
Problem is: I don't even know where the so-called old files/versions of Net::SFTP::Foreign on my Win7 box. I am new to Perl. I am not new to programming. There must be some perl commands that will uninstall the specified version of a module. ________________________________ From: Salvador Fandino <sfa...@ya...> To: Anthony Liu <ant...@ya...> Cc: "Ssh...@li..." <Ssh...@li...> Sent: Monday, February 13, 2012 11:31 AM Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? >________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 5:03 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Well, you are right, I adapted your script, ran it and I got this: > > >This is Net::SFTP::Foreign 1.57 running on perl v5.12.3 on MSWin32 > > > >Now, before I make other tests, how can I have Perl pick up my Net::SFTP:Foreign 1.69? Delete the files from the old version from your hard disk. Add the following lines to your script, to see find it: use Net::SFTP::Foreign; use Data::Dumper; print Dump \%INC; |
From: Salvador F. <sfa...@ya...> - 2012-02-13 16:51:43
|
>________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 5:44 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Problem is: I don't even know where the so-called old files/versions of Net::SFTP::Foreign on my Win7 box. I am new to Perl. I am not new to programming. There must be some perl commands that will uninstall the specified version of a module. I don't think there is any command to uninstall modules on Strawsberry Perl. The location of the old files can be found with the following perl code: use Net::SFTP::Foreign; print Dumper "$INC{'Net/SFTP/Foreign.pm'}\n"; Or just use your preferred OS search facility to find files and directories named "Foreign.pm" and "Foreign" respectively. |
From: Anthony L. <ant...@ya...> - 2012-02-13 18:04:09
|
OK, let's do this step by step. I have renamed Foreign.pm to Foreign.old.pm. And naturally, if I issue perldoc Net::SFTP::Foreign I get this: No documentation found for "Net::SFTP::Foreign". I guess I will need to specify the PERLLIB path. ________________________________ From: Salvador Fandino <sfa...@ya...> To: Anthony Liu <ant...@ya...> Cc: "Ssh...@li..." <Ssh...@li...> Sent: Monday, February 13, 2012 11:51 AM Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? >________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 5:44 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >Problem is: I don't even know where the so-called old files/versions of Net::SFTP::Foreign on my Win7 box. I am new to Perl. I am not new to programming. There must be some perl commands that will uninstall the specified version of a module. I don't think there is any command to uninstall modules on Strawsberry Perl. The location of the old files can be found with the following perl code: use Net::SFTP::Foreign; print Dumper "$INC{'Net/SFTP/Foreign.pm'}\n"; Or just use your preferred OS search facility to find files and directories named "Foreign.pm" and "Foreign" respectively. |
From: Anthony L. <ant...@ya...> - 2012-02-13 18:59:40
|
I wasn't aware this cpan utility, much like apt-get. So, I have installed Net::SFTP::Foreign 1.69. Confirmed with your script: C:\PerlTests>perl ./fandino.pl This is Net::SFTP::Foreign 1.69 running on perl v5.12.3 on MSWin32 Now, if I run the following code to try to connect to my ssh server: use Net::SFTP::Foreign 1.69; $host = "my.ssh.server.com"; $port = 22; $user = "aliu"; $publickey="id_dsa.pub"; $privatekey = "id_dsa"; $sshcmd = "plink.exe"; %args = ("port", $port, "key_path", $privatekey, "user", $user, "ssh_cmd", $sshcmd); my $sftp = Net::SFTP::Foreign->new(host=>$host, %args); if ($sftp->error) { my ( $code, $error_name, $error_message ) = $sftp->error; print "sftp error[$code] $error_name: $error_message \n"; } else { print "Success!"; } I get this: C:\PerlTests>perl ./test.pl The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server's rsa2 key fingerprint is: ssh-rsa 2048 3c:3c:ad:17:98:88:c5:1d:95:9e:1b:d6:4e:05:b0:a9 If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter "n". If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n) Connection abandoned. sftp error[Connection to remote server is broken] : C:\PerlTests> ________________________________ From: Salvador Fandino <sfa...@ya...> To: Anthony Liu <ant...@ya...> Sent: Monday, February 13, 2012 1:25 PM Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? >________________________________ > From: Anthony Liu <ant...@ya...> >To: Salvador Fandino <sfa...@ya...> >Cc: "Ssh...@li..." <Ssh...@li...> >Sent: Monday, February 13, 2012 7:03 PM >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key for authentication? > > >OK, let's do this step by step. I have renamed Foreign.pm to Foreign.old.pm. And naturally, if I issue > > >perldoc Net::SFTP::Foreign > > >I get this: > > >No documentation found for "Net::SFTP::Foreign". > > >I guess I will need to specify the PERLLIB path. Just run cpan Net::SFTP::Foreign To download and install the latest version of the module from CPAN. If that doesn't work (for instance, if the machine is not connected to the internet), In order to keep you going, just copy the Foreign.pm file and Foreign directory from the Net-SFTP-Foreign-1.69.tar.gz distribution to the same place where you found the old ones, and try your script again. |
From: Steve P. <st...@fo...> - 2012-02-13 23:17:36
Attachments:
smime.p7s
|
This is putty telling you that it doesn't know about this host as the host key isn't in puttys cache. You can add this by using putty manually to connect to the host and telling it to save the key in its cache. The reason the script fails is it (putty) is asking for an interactive response but, being a script there is no way to get this and so it exits. -- Steve. On 14/02/2012 5:58 AM, Anthony Liu wrote: > I wasn't aware this cpan utility, much like apt-get. So, I have > installed Net::SFTP::Foreign 1.69. Confirmed with your script: > > C:\PerlTests>perl ./fandino.pl > This is Net::SFTP::Foreign 1.69 running on perl v5.12.3 on MSWin32 > > Now, if I run the following code to try to connect to my ssh server: > > use Net::SFTP::Foreign 1.69; > > $host = "my.ssh.server.com"; > $port = 22; > $user = "aliu"; > $publickey="id_dsa.pub"; > $privatekey = "id_dsa"; > $sshcmd = "plink.exe"; > > %args = ("port", $port, "key_path", $privatekey, "user", $user, > "ssh_cmd", $sshcmd); > > my $sftp = Net::SFTP::Foreign->new(host=>$host, %args); > > if ($sftp->error) > { > my ( $code, $error_name, $error_message ) = $sftp->error; > print "sftp error[$code] $error_name: $error_message \n"; > > } > else > { > print "Success!"; > } > > I get this: > > C:\PerlTests>perl ./test.pl > The server's host key is not cached in the registry. You > have no guarantee that the server is the computer you > think it is. > The server's rsa2 key fingerprint is: > ssh-rsa 2048 3c:3c:ad:17:98:88:c5:1d:95:9e:1b:d6:4e:05:b0:a9 > If you trust this host, enter "y" to add the key to > PuTTY's cache and carry on connecting. > If you want to carry on connecting just once, without > adding the key to the cache, enter "n". > If you do not trust this host, press Return to abandon the > connection. > Store key in cache? (y/n) Connection abandoned. > sftp error[Connection to remote server is broken] : > > C:\PerlTests> > > > > > > > > > ------------------------------------------------------------------------ > *From:* Salvador Fandino <sfa...@ya...> > *To:* Anthony Liu <ant...@ya...> > *Sent:* Monday, February 13, 2012 1:25 PM > *Subject:* Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key > for authentication? > > >________________________________ > > > From: Anthony Liu <ant...@ya... > <mailto:ant...@ya...>> > >To: Salvador Fandino <sfa...@ya... <mailto:sfa...@ya...>> > >Cc: "Ssh...@li... > <mailto:Ssh...@li...>" > <Ssh...@li... > <mailto:Ssh...@li...>> > >Sent: Monday, February 13, 2012 7:03 PM > >Subject: Re: [Ssh-sftp-perl-users] Fwd: How to load my private DSA key > for authentication? > > > > > >OK, let's do this step by step. I have renamed Foreign.pm > <http://Foreign.pm> to Foreign.old.pm <http://Foreign.old.pm>. And > naturally, if I issue > > > > > >perldoc Net::SFTP::Foreign > > > > > >I get this: > > > > > >No documentation found for "Net::SFTP::Foreign". > > > > > >I guess I will need to specify the PERLLIB path. > > > Just run > > cpan Net::SFTP::Foreign > > To download and install the latest version of the module from CPAN. > > > If that doesn't work (for instance, if the machine is not connected to > the internet), In order to keep you going, just copy the Foreign.pm file > and Foreign directory from the Net-SFTP-Foreign-1.69.tar.gz distribution > to the same place where you found the old ones, and try your script again. > > > > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > > > > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users |