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

如何将Net::SSH::Perl与公钥一起使用?,perl,ssh,ssh-keys,Perl,Ssh,Ssh Keys,我正在尝试使用Net::SSH::Perl使用公钥连接以下代码: my $ssh = Net::SSH::Perl->new($host, debug=>1) || die ...... 我将密钥放在/root/.ssh/id\u rsa和/root/.ssh/identity中 它似乎不是试图使用公钥,而是试图询问密码: 我得到这个输出: localhost: Sent key-exchange init (KEXINIT), wait response. localhost:

我正在尝试使用
Net::SSH::Perl
使用公钥连接以下代码:

my $ssh = Net::SSH::Perl->new($host, debug=>1) || die ......
我将密钥放在/root/.ssh/id\u rsa和/root/.ssh/identity中

它似乎不是试图使用公钥,而是试图询问密码:

我得到这个输出:

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. localhost:已发送密钥交换初始化(KEXINIT),等待响应。 localhost:算法,c->s:3des cbc hmac-sha1无 localhost:算法,s->c:3des cbc hmac-sha1无 localhost:正在进入Diffie Hellman组1密钥交换。 localhost:已发送DH公钥,正在等待答复。 localhost:收到主机密钥,键入“ssh dss”。 localhost:主机“10.212.1.201”已知并与主机密钥匹配。 localhost:计算共享密钥。 localhost:正在验证服务器签名。 localhost:正在等待NEWKEYS消息。 localhost:发送新密钥。 localhost:启用加密/MAC/压缩。 localhost:发送用户身份验证服务的请求。 localhost:已接受服务:ssh userauth。 localhost:正在尝试空用户身份验证请求。 localhost:可以继续的身份验证方法:公钥、带麦克风的gssapi、密码。 localhost:下一个要尝试的方法是publickey。 localhost:下一个要尝试的方法是密码。 localhost:正在尝试密码身份验证。 localhost:将不会在批处理模式下查询密码短语。 localhost:可以继续的身份验证方法:公钥、带麦克风的gssapi、密码。 localhost:下一个要尝试的方法是publickey。 localhost:下一个要尝试的方法是密码。 localhost:正在尝试密码身份验证。 localhost:将不会在批处理模式下查询密码短语。 localhost:可以继续的身份验证方法:公钥、带麦克风的gssapi、密码。 localhost:下一个要尝试的方法是publickey。 localhost:下一个要尝试的方法是密码。 localhost:正在尝试密码身份验证。 localhost:将不会在批处理模式下查询密码短语。 localhost:可以继续的身份验证方法:公钥、带麦克风的gssapi、密码。 localhost:下一个要尝试的方法是publickey。 localhost:下一个要尝试的方法是密码。
找到它:必须手动指定密钥文件位置:

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