如何将 Net::SSH::Perl 与公钥一起使用?

编程入门 行业动态 更新时间:2024-10-15 20:21:36
本文介绍了如何将 Net::SSH::Perl 与公钥一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 Net::SSH::Perl 通过此代码使用公钥进行连接:

my $ssh = Net::SSH::Perl->new($host, debug=>1) ||死 ......

我把密钥放在/root/.ssh/id_rsa 和/root/.ssh/identity

它似乎不是试图使用公钥,而是试图要求输入密码:

我得到这个输出:

本地主机:发送密钥交换初始化(KEXINIT),等待响应.本地主机:算法,c->s:3des-cbc hmac-sha1 无本地主机:算法,s->c:3des-cbc hmac-sha1 无本地主机:进入 Diffie-Hellman Group 1 密钥交换.localhost:发送DH公钥,等待回复.本地主机:收到主机密钥,输入ssh-dss".本地主机:主机 '10.212.1.201' 已知并匹配主机密钥.localhost:计算共享密钥.本地主机:验证服务器签名.本地主机:等待 NEWKEYS 消息.本地主机:发送新密钥.本地主机:启用加密/MAC/压缩.localhost:发送用户认证服务请求.本地主机:接受服务:ssh-userauth.本地主机:尝试空的用户身份验证请求.localhost:可以继续的认证方法:publickey、gssapi-with-mic、password.本地主机:下一个尝试的方法是公钥.本地主机:下一个尝试的方法是密码.本地主机:尝试密码认证.localhost:不会在批处理模式下查询密码.localhost:可以继续的认证方法:publickey、gssapi-with-mic、password.本地主机:下一个尝试的方法是公钥.localhost:下一个尝试的方法是密码.本地主机:尝试密码认证.localhost:不会在批处理模式下查询密码.localhost:可以继续的认证方法:publickey、gssapi-with-mic、password.本地主机:下一个尝试的方法是公钥.localhost:下一个尝试的方法是密码.本地主机:尝试密码认证.localhost:不会在批处理模式下查询密码.localhost:可以继续的认证方法:publickey、gssapi-with-mic、password.本地主机:下一个尝试的方法是公钥.localhost:下一个尝试的方法是密码.

解决方案

发现:必须手动指定密钥文件位置:

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

I'm trying to use Net::SSH::Perl to connect using public keys with this code:

my $ssh = Net::SSH::Perl->new($host, debug=>1) || die ......

I put the key in /root/.ssh/id_rsa and /root/.ssh/identity

It seems that it's not trying to use the public key and instead trying to ask for a password:

I get this output:

localhost: Sent key-exchange init (KEXINIT), wait response. localhost: Algorithms, c->s: 3des-cbc hmac-sha1 none localhost: Algorithms, s->c: 3des-cbc hmac-sha1 none localhost: Entering Diffie-Hellman Group 1 key exchange. localhost: Sent DH public key, waiting for reply. localhost: Received host key, type 'ssh-dss'. localhost: Host '10.212.1.201' is known and matches the host key. localhost: Computing shared secret key. localhost: Verifying server signature. localhost: Waiting for NEWKEYS message. localhost: Send NEWKEYS. localhost: Enabling encryption/MAC/compression. localhost: Sending request for user-authentication service. localhost: Service accepted: ssh-userauth. localhost: Trying empty user-authentication request. localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password. localhost: Next method to try is publickey. localhost: Next method to try is password. localhost: Trying password authentication. localhost: Will not query passphrase in batch mode. localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password. localhost: Next method to try is publickey. localhost: Next method to try is password. localhost: Trying password authentication. localhost: Will not query passphrase in batch mode. localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password. localhost: Next method to try is publickey. localhost: Next method to try is password. localhost: Trying password authentication. localhost: Will not query passphrase in batch mode. localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password. localhost: Next method to try is publickey. localhost: Next method to try is password.

解决方案

found it: have to specify the key file location manually:

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

更多推荐

如何将 Net::SSH::Perl 与公钥一起使用?

本文发布于:2023-10-07 13:11:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   公钥   SSH   Net   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!