【发布时间】:2016-09-26 23:10:52
【问题描述】:
我正在尝试使用 Net::SSH2 连接到远程 SSH 服务器。命令行 ssh 工作正常。不过,我似乎无法找出正确的基于 auth_host 的参数
这是我的代码:
use Net::SSH2;
my $ssh = Net::SSH2->new();
$ssh->debug(1);
$ssh->trace(-1);
$ssh->connect('remotehost.remotedomain.tld') or die;
$ssh->auth_hostbased('username',
'ssh-rsa AAAAB3Nz[..]C0JoaFF9 root@myhost',
'-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,FA97214E87562096A7E480C82DAE5EB4
XIMKnj9k[..]kpRo5V
-----END RSA PRIVATE KEY-----',
'myhost.mydomain.tld',
'username',
'keypassword') or die;
sn-p 在 @ $ssh->auth_hostbased 中死去,只有一个 'Net::SSH2::DESTROY object 0xe17de0'。设置跟踪似乎无关紧要。用 $ssh->die_with_error 替换 die 会引发“die_with_error 不是有效的 Net::SSH2 宏”。下载当前 0.53 版本的 Net:SSH2 不起作用,因为脚本不再编译:'Net::SSH2 object version 0.44 does not match bootstrap parameter 0.53'
感谢任何有关正确参数格式或替代模块的帮助。
【问题讨论】:
-
您将密码短语作为最后一个参数传递,对吗?你从命令行连接时使用了什么认证方式?
-
这在 bash 中有效:'ssh -i /root/.ssh/privkey username@remotehost.remotedomain.tld ls -l' 然后我输入密码来解锁 privkey
-
使用
auth_publickey方法。顺便说一句,最新的 Net::SSH2 版本是 0.60。 -
不高兴。没有错误消息可以使用,这有点令人沮丧。 strace 揭示了这一点: read(5, "-----BEGIN RSA PRIVATE KEY-----\n"..., 4096) = 1766 ||关闭(5) = 0 || munmap(0x7f10a0dd8000, 4096) = 0 ||写(2,“死于 ./nrp.pl 第 21 行。\n”,26死于 ./nrp.pl 第 21 行。)= 26 || write(2, "Net::SSH2::DESTROY object 0xf73d"..., 35Net::SSH2::DESTROY object 0xf73dc0 ) = 35 鉴于没有网络写入,我猜想 Net:SSH2 不喜欢这个键
-
在调用
die之前打印Net::SSH2错误:print STDERR join(' ', $ssh->error);
标签: perl ssh public-key