簡體   English   中英

與Perl“ Net :: SFTP”模塊的SFTP連接失敗

[英]SFTP connection failure with Perl “Net::SFTP” module

我試圖使用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”中的“%AUTH_MAP”中刪除了密碼身份驗證/Net/SSH/Perl/AuthMgr.pm”,並按預期連接! 有沒有辦法強制使用僅/第一密鑰身份驗證?

提前致謝! 麥克風

禁用密碼身份驗證(僅身份驗證密鑰)的代碼為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM