1

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.

Abdel Raoof Olakara
  • 19,223
  • 11
  • 88
  • 133
Ron
  • 29
  • 1
  • 4

3 Answers3

3

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);
Erik
  • 66
  • 1
0

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

Wivani
  • 2,036
  • 22
  • 28
0

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.

piotrpo
  • 12,398
  • 7
  • 42
  • 58