Linux ssh.pl第17行的权限被拒绝-$ssh->;登录($user,$password);

Linux ssh.pl第17行的权限被拒绝-$ssh->;登录($user,$password);,linux,perl,ssh,Linux,Perl,Ssh,我正试图通过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

我正试图通过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
感谢任何帮助,如果需要更多信息,请询问我


谢谢:)

因此,要从收件人的评论和回复中获得正式答复:

使用密钥并手动定义密钥文件位置:

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

这是一个旧线程,但它是在我搜索与Net::SSH::Perl相关的其他项目时出现的

这假定代码中显示的密码不是空字符串,实际上是经过编辑但有效的密码

我遇到了这个问题,问题是我假设在以交互方式登录远程主机时使用了密码身份验证。实际上,我使用的是
键盘交互
身份验证,而
密码
身份验证在sshd服务器上被禁用


我在我的
/etc/ssh/sshd_config
中添加了
PasswordAuthentication yes
,重新启动了sshd进程,Net::ssh::Perl的一切都很好。

我猜您在
$password
中拥有真正的密码。您可以从命令行ssh吗?另外,您也不想将
挂载的
放在backticks中。我可以从命令行进行ssh,它的工作方式是我不需要ssh的密码,因此我不确定是否应该在密码标量中分配任何内容,这就是为什么我将其保留为空的原因。我之所以在backticks中使用这个脚本,是因为挂载的是一个不打印但可执行的脚本?我确实认为,允许root用户在没有密码的情况下从一台机器ssh到另一台机器是一个安全漏洞。如果您将
mounted
放在backticks中,它将在您的本地计算机上运行mounted,并尝试将其输出作为命令发送到远程计算机。这就是我们公司的安全设置方式。我们有许多脚本,只有当您是root用户时才可执行,而且我们的用户帐户也没有密码。啊,我能从背面看到你的观点。有没有办法解决ssh->login问题呢?也许可以看看这个问题。如果您不使用密码登录,我假设您使用的是密钥文件。