我试图将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感谢您的帮助,如果需要更多的信息,请咨询我。
谢谢:)
发布于 2014-05-04 01:04:05
因此,要从AKHolland的评论和Arthur Ulfeldt对his own question的回答中得到一个正式的答案:
使用键并手动定义密钥文件位置:
@KEYFILE = ("/root/.ssh/id_rsa");
$ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)发布于 2016-05-09 21:44:01
这是一个旧线程,但它是在我搜索与Net::SSH::Perl相关的其他项时出现的。
这假设代码中显示的密码不是空字符串,实际上是经过修改但有效的密码。
我遇到了这样的问题,问题是我假设在以交互方式登录到远程主机时使用密码身份验证。实际上,我使用的是keyboard-interactive身份验证,password身份验证在sshd服务器上被禁用。
我将PasswordAuthentication yes添加到我的/etc/ssh/sshd_config中,重新启动sshd进程,所有这些都与Net::SSH::Perl很好。
https://stackoverflow.com/questions/23430966
复制相似问题