1

我正在尝试使用 MINA SSHD 编写一个 SSH 客户端,连接由 openSSH 生成的身份文件(id_rsa以及相应的公钥id_rsa.pub

文档说要按照这些思路写一些东西:

    SshClient client = SshClient.setUpDefaultClient();
    client.start();

    // using the client for multiple sessions...
    try (ClientSession session = client.connect(user, host, port)
                .verify(1000)
                .getSession()) {
        session.addPublicKeyIdentity(/* ...key-pair... */);
        session.auth().verify(1000);
        // ...
    }
    client.stop();

如何构建方法的参数addPublicKeyIdentity?如何将我的身份文件转换为KeyPair?

非常感谢

4

1 回答 1

0

您可以尝试org.apache.sshd.common.keyprovider.FileKeyPairProvider改用。

例子:

FileKeyPairProvider provider = new FileKeyPairProvider(/*Path to your privateKey*/);
provider.setPasswordFinder(FilePasswordProvider.of(/*your private key passphrase*/));
session.setKeyIdentityProvider(provider);
于 2022-01-25T14:35:29.920 回答