Perl“ Net :: SFTP”模块的SFTP连接失败

时间:2019-05-05 05:33:30

标签: perl ssh ftp sftp openssh

我正在尝试使用Perl连接到SFTP服务器,但出现以下连接错误:Permission denied at /app/perl-5.24.3/lib/site_perl/5.24.3/Net/SFTP.pm line 63.

我的连接代码“ sftp_test2.pl”:

use strict;
use warnings;

use Net::SFTP;

my $server   = 'downloads-server';
my $user     = 'user';
my $port     = "10022";
my $password = '';

my %args = (
     user => "$user",
     port => "$port",
     ssh_args => {
         user => "$user",
         identity_files => [ 'path/sftp_download'],
         port => "$port",
         protocol=>'2,1',
         debug => 1,
     }
);

my $sftp=Net::SFTP->new($server, %args) or die "could not open connection to $server\n";

执行:

$>perl sftp_test2.pl
Reading configuration data path/home/.ssh/config
Reading configuration data /etc/ssh_config
Connecting to downloads-server, port 10022.
Remote version string: SSH-2.0-CrushFTPSSHD
Remote protocol version 2.0, remote software version CrushFTPSSHD
Net::SSH::Perl Version 2.14, protocol version 2.0.
No compat match: CrushFTPSSHD.
Connection established.
Sent key-exchange init (KEXINIT), waiting for response.
Using diffie-hellman-group-exchange-sha256 for key exchange
Host key algorithm: ssh-rsa
Algorithms, c->s: aes256-ctr hmac-sha2-512-etm@openssh.com none
Algorithms, s->c: aes256-ctr hmac-sha2-512-etm@openssh.com none
Entering Diffie-Hellman Group Exchange.
SSH2_MSG_KEX_DH_GEX_REQUEST(2048<4096<8192) sent
Sent DH Group Exchange request, waiting for reply.
Received 4096 bit DH Group Exchange reply.
Generating new Diffie-Hellman keys.
Entering Diffie-Hellman key exchange.
Sent DH public key, waiting for reply.
Received host key, type 'ssh-rsa'.
Host 'downloads-server' is known and matches the host key.
Verifying server signature.
Send NEWKEYS.
Waiting for NEWKEYS message.
Enabling encryption/MAC/compression.
Sending request for user-authentication service.
Service accepted: ssh-userauth.
Trying empty user-authentication request.
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Trying password authentication.
Will not query passphrase in batch mode.
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Trying password authentication.
Will not query passphrase in batch mode.
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Trying password authentication.
Will not query passphrase in batch mode.
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Next method to try is publickey.
Publickey: testing agent key 'my-server'
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Next method to try is publickey.
Publickey: testing agent key 'path/home/.ssh/id_rsa'
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Next method to try is publickey.
Trying pubkey authentication with key file 'path/sftp_download'
Authentication methods that can continue: password,publickey,keyboard-interactive.
Next method to try is password.
Next method to try is publickey.
Permission denied at /app/perl-5.24.3/lib/site_perl/5.24.3/Net/SFTP.pm line 63.

我认为这与我的私钥有关,但是我可以通过Unix命令进行连接:

  

sftp -oPort = 10022 -oIdentityFile = path / sftp_download user @ downloads-server   
正在连接下载服务器...   
sftp>

我试图在许多文章中找到解决方案,并且尝试了几种代码变体,但是都没有成功。

我做错什么了吗? 这是一个已知的错误吗?任何解决方法? 如何调试它以查找原因(我对SSH / FTP不太熟悉)。

编辑: 我怀疑这可能与使用密码的多次连接失败尝试有关,因此我从文件“ app / perl-5.24.3 / lib / site_perl / 5.24.3 / x86_64-linux / Net”中的“%AUTH_MAP”中删除了密码身份验证/SSH/Perl/AuthMgr.pm”,它已按预期连接! 有办法强制使用仅/第一密钥身份验证吗?

提前谢谢! 迈克

1 个答案:

答案 0 :(得分:0)

禁用密码身份验证(仅身份验证密钥)的代码为:

ssh_args => {
  user    => $user,
  options => [ 'PasswordAuthentication no' ],
  identity_files => [ 'path/sftp_download'],
  port     => $port,
  protocol =>'2,1',
  debug    => 1,
}
相关问题