tags:

views:

70

answers:

2

Can anyone give me an example of private/public key authentication in sshj?

In sshj what's the command line equivalent of,

ssh -i /path/to/mykey.private username@host

I tried (error handling omitted),

final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("host");
ssh.authPublickey("username", "/path/to/mykey.private");
final Session session = ssh.startSession();
...

but in the log statements I see,

DEBUG net.schmizz.sshj.SSHClient - Attempting to load key from: /path/to/mykey.private
WARN  net.schmizz.sshj.SSHClient - Could not load keys due to: {}
net.schmizz.sshj.common.SSHException: No provider available forUnknown key file
    at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:482) ~[sshj-0.3.0.jar:na]
...
Exception in thread "main" 10:49:55.943 [reader] DEBUG
net.schmizz.sshj.transport.Reader - Stopping
net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods

Thanks, Everett

A: 

Sounds like your private key isn't being loaded? Did you check that the permissions on it are correct, and that you have the correct path?

Also, note, looks like your argument to ssh.authPublickey should be a string, and at least in the code you pasted, it's not?

zigdon
The permissions are okay. Private keys can only be owner rw and I'm running the Java app as the owner. The path is correct too. The arguments are Strings in my real code, I'll update the question.
Everett Toews
+1  A: 

Answered on the sshj google group. It's probably a bug with the library.

shikhar