To enable public key authentication , you need to use one of the JSch.addIdentity
methods.
They use the public and private keys in the OpenSSH key format, so make sure you export it from PuTTY in this format. (JSch does not understand the native PuTTY format, although you can write an adapter that implements the Identity interface by disassembling it yourself.)
The personalities added to JSch are global, not sessions. This is usually not a problem, because JSch will check all authentication methods that are supported by itself and the server in order, and public key authentication is usually performed before password authentication.
All authentication methods require a username (usually the name of the login account).
With public key authentication, the public key must be somehow previously available for the server. For OpenSSH sshd, the public key must be specified in ~/.ssh/authorized_keys
. (If you have only one public key, just copy it to this file, if you have several (each of which will be allowed), each of them should be on the same line.)
Therefore, after setting the identifier, it should work outside the box.
If you want to make sure that the first session uses password authentication, and the second (tunneled) uses the public key, you can use the configuration per session by overriding the global one:
tunnelSession.setConfig("PreferredAuthentications", "password"); innerSession.setConfig("PreferredAuthentications", "publickey");
(These are comma-separated lists, here is one element.)
About the example of ProxySSH, that is, I (with some help from the author of JSch, Atsuhiko Yamanaka). I should add this information to the Wiki page, maybe.