代码之家  ›  专栏  ›  技术社区  ›  Arthur Ulfeldt

如何将net::ssh::perl与公钥一起使用?

  •  7
  • Arthur Ulfeldt  · 技术社区  · 14 年前

    我想用 Net::SSH::Perl 要使用公钥连接此代码,请执行以下操作:

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

    我把密钥放在/root/.ssh/id_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.
    
    1 回复  |  直到 13 年前
        1
  •  10
  •   Arthur Ulfeldt    14 年前

    找到它:必须手动指定密钥文件位置:

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