SSHJ Example of Public Key Auth from File

后端 未结 2 1731
清酒与你
清酒与你 2021-01-04 21:32

Can someone give me an example of using SSHJ for Public Key Authentication? I realise this question is essentially identical to ssh example of private/public key authenticat

相关标签:
2条回答
  • 2021-01-04 21:45

    I just had this issue as well. I ended up changing

    client.authPublickey(user, "id_rsa.pub")
    

    to

    client.authPublickey(user, client.loadKeys("id_rsa"))
    
    0 讨论(0)
  • 2021-01-04 21:55

    We built the overthere framework on top of SSHJ. Which can connect also connect using key files. The following piece of code should work, but make sure you add the bouncycastle library to your classpath.

    SSHClient client = new SSHClient();
    String username = "johndoe";
    File privateKey = new File("~/.ssh/id_rsa");
    KeyProvider keys = client.loadKeys(privateKey.getPath());
    client.authPublickey(username, keys);
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题