Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Net::SFTP permission denied but sftp works

by Anonymous Monk
on Aug 18, 2003 at 07:34 UTC ( [id://284493]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to implement a secure FTP transfer to a remote machine. The remote machine does NOT permit an SSH telnet session, but will allow SFTP sessions. I am able to connect using the command line 'sftp'. However when connecting to the same machine using Net::SFTP I get the following error messages:

local: Connecting to ***********, port 22.
local: Remote protocol version 2.0, remote software version OpenSSH_3.0.2p1
local: Net::SSH::Perl Version 1.23, protocol version 2.0.
local: No compat match: OpenSSH_3.0.2p1.
local: Connection established.
local: Sent key-exchange init (KEXINIT), wait response.
local: Algorithms, c->s: 3des-cbc hmac-sha1 none
local: Algorithms, s->c: 3des-cbc hmac-sha1 none
local: Entering Diffie-Hellman Group 1 key exchange.
local: Sent DH public key, waiting for reply.
local: Received host key, type 'ssh-dss'.
local: Host '****************' is known and matches the host key.
local: Computing shared secret key.
local: Verifying server signature.
local: Waiting for NEWKEYS message.
local: Enabling incoming encryption/MAC/compression.
local: Send NEWKEYS, enable outgoing encryption/MAC/compression.
local: Sending request for user-authentication service.
local: Service accepted: ssh-userauth.
local: Trying empty user-authentication request.
local: Authentication methods that can continue: publickey.
local: Next method to try is publickey.
Permission denied at /opt/perl/lib/site_perl/5.6.1/Net/SFTP.pm line 37

Line 37 of SFTP.pm is:

$ssh->login($param{user}, $param{password});

The remote SFTP host uses public/private keys and only needs a username (ie. user@host) to login - all of which is in my code:

use Net::SFTP; my %args = (ssh_args => []); $args{user} = $user; push @{ $args{ssh_args} }, port => 22; my $sftp = Net::SFTP->new($host,%args);
Any ideas what the problem might be?

Replies are listed 'Best First'.
Re: Net::SFTP permission denied but sftp works
by CombatSquirrel (Hermit) on Aug 18, 2003 at 08:06 UTC
    First of all, you are not supplying the password for the user, which will give you the local: Trying empty user-authentication request. error message. Secondly, IMHO, ssh_args is a list of named arguments, and therefore a hash. You might want to change
    my %args = (ssh_args => [] ); ... push @{ $args{ssh_args} }, port => 22;

    to
    my %args = (ssh_args => {} ); ... $args{ssh_args}->{port} = 22;

    The revised code shold look somewhat like this:
    use Net::SFTP; my %args = (ssh_args => {}); $args{user} = $user; $args{password} = $pass; $args{ssh_args}->{port} = 22; my $sftp = Net::SFTP->new($host,%args);

    Everything above is untested, but I think that it'll work for you. Let me know if it does not.
Re: Net::SFTP permission denied but sftp works
by zengargoyle (Deacon) on Aug 18, 2003 at 09:59 UTC

    try this, pass in an empty password.

    $args{password} = '';

    and cross your fingers. you might also want to explicitly specify the path to your identity file. doing these made Net::SSH work for me with keys, never tried SFTP.

Re: Net::SFTP permission denied but sftp works
by wirrwarr (Monk) on Aug 18, 2003 at 09:12 UTC
    Are you sure SFTP means "secure ftp" for the machine you're connecting to? SFTP is also the acronym for "simple ftp" (rfc 913), which is not secure at all.
Re: Net::SFTP permission denied but sftp works
by ant9000 (Monk) on Aug 18, 2003 at 09:27 UTC
    Take a deeper look at what happens inside the login() method. Since the module should try to authenticate with a public key, my guess is that the key file is unreadable to the script.
Re: Net::SFTP permission denied but sftp works
by wadjet (Initiate) on Aug 19, 2003 at 05:14 UTC
    Thanks everyone. I discovered that perl wasn't reading the keys at all, due to the fact that the SSH config file is located under /opt/ssh/etc on unix (my machine) as opposed to the expected /etc... directory that Net::SFTP looks for. I simply copied the /opt/ssh/etc/ssh_config file to ~/.ssh and uncommented the IdentityFile line with ~/.ssh/id_rsa and all works!
      Could you please paste your modified code which is working here? even I am facing the same issue

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-05-21 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found