How do I connect 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);