SSHJ Example of Public Key Auth from File
We built the overthere framework on top of SSHJ. Which can connect also connect using key files. The following piece of code should work, but make sure you add the bouncycastle library to your classpath.
SSHClient client = new SSHClient();
String username = "johndoe";
File privateKey = new File("~/.ssh/id_rsa");
KeyProvider keys = client.loadKeys(privateKey.getPath());
client.authPublickey(username, keys);
Hope that helps.
I just had this issue as well. I ended up changing
client.authPublickey(user, "id_rsa.pub")
to
client.authPublickey(user, client.loadKeys("id_rsa"))