繁体   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