开发者

Java - Authentication with public key and passphrase - j2ssh

How do I connec开发者_开发问答t to server with public key and passphrase (I have the public key and I know the passphrase. I'm using com.sshtools.j2ssh library but I can't see an option to set passphrase. The problem is, even though I have the public key, the server keep asking for passphrase.

Thanks. Ron.


When you instantiate the SshPrivateKeyFile you can then call toPrivateKey on that object to create a SshPrivateKey object. That toPrivateKey method takes a string that is your passphrase. If you do not have a passphrase, pass an empty string (or a null I believe works also). Here is a sample.

PublicKeyAuthenticationClient sshClient = new PublicKeyAuthenticationClient();

SshPrivateKeyFile sshPrivKeyFile = SshPrivateKeyFile.parse(new File(keyFile));
SshPrivateKey sshPrivKey = sshPrivKeyFile.toPrivateKey("passphrase");
sshClient.setKey(sshPrivKey);


Are you sure, that server is properly configured? If it's set to key auth no password should be needed except keystore password. Try to connect using putty or something like that. I also recommend you to try Ganymed SSH I have used it in couple of projects and there was no problems with that even using quite advanced features such tunnels, scp, etc.


Check the API of j2ssh for decrypt/encrypt methods. Usually those are used to send for authentication.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜