簡體   English   中英

在ssh.pl第17行拒絕權限 - $ ssh-> login($ user,$ password);

[英]Permission denied at ssh.pl line 17 - $ssh->login($user, $password);

我試圖ssh到一台機器並運行一個使用perl腳本mounted的命令。

我一直收到錯誤:

Permission denied at ssh.pl line 17

第17行:

$ssh->login($user, $password);

誰能幫我理解為什么?

這是我的完整腳本:

#!/usr/local/bin/perl -w

use strict;
use warnings;
require Net::SSH::Perl;

#declare our login vars...

my $user = "root";
my $password = "";
my $server = "beccles";

#Setup our SSH Connection...
my $ssh = Net::SSH::Perl->new($server,port=>22,protocol=>2, debug => 1);

#Initiate out conneciton to the server...
$ssh->login($user, $password);

# Declare our variable for the request...
my $mounts;
my $name;

# Run our SSH Command and retrieve the output...
($mounts) = $ssh->cmd(`mounted`);
($name) = $ssh->cmd("uname -n");

# Print Output
chomp $name;
#print "\n$mounts\n";

exit 0;

這是調試ssh連接后得到的輸出:

calver: Remote protocol version 2.0, remote software version OpenSSH_5.3
calver: Net::SSH::Perl Version 1.37, protocol version 2.0.
calver: No compat match: OpenSSH_5.3
calver: Connection established.
calver: Sent key-exchange init (KEXINIT), wait response.
calver: Algorithms, c->s: 3des-cbc hmac-sha1 none
calver: Algorithms, s->c: 3des-cbc hmac-sha1 none
calver: Entering Diffie-Hellman Group 1 key exchange.
calver: Sent DH public key, waiting for reply.
calver: Received host key, type 'ssh-dss'.
calver: Host 'beccles' is known and matches the host key.
calver: Computing shared secret key.
calver: Verifying server signature.
calver: Waiting for NEWKEYS message.
calver: Send NEWKEYS.
calver: Enabling encryption/MAC/compression.
calver: Sending request for user-authentication service.
calver: Service accepted: ssh-userauth.
calver: Trying empty user-authentication request.
calver: Authentication methods that can continue: publickey,gssapi-keyex,gssapi-   
with-mic,keyboard-interactive.
calver: Next method to try is publickey.
calver: Publickey: testing agent key '/u/blh/.ssh/blh_git'
calver: Authentication methods that can continue: publickey,gssapi-keyex,gssapi-   
with-mic,keyboard-interactive.
calver: Next method to try is publickey.
Permission denied at ssh.pl line 17

感謝任何幫助,如果需要更多信息,請問我。

謝謝 :)

所以要從AKHolland的評論和Arthur Ulfeldt他自己的問題的答案中得到正式答案:

使用鍵並手動定義您的密鑰文件位置:

@KEYFILE = ("/root/.ssh/id_rsa");
$ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)

這是一個舊線程,但它在我搜索與Net :: SSH :: Perl相關的其他項目時出現了。

這假設代碼中顯示的密碼不是空字符串,實際上是一個編輯但有效的密碼。

我跑到這里,問題是我假設我在交互式登錄遠程主機時使用密碼驗證。 實際上,我使用的是keyboard-interactive身份驗證,並且在sshd服務器上禁用了password身份驗證。

我在/etc/ssh/sshd_config添加了PasswordAuthentication yes ,重新啟動了sshd進程,Net :: SSH :: Perl一切都很好。

暫無
暫無

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

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