I'm having an issue with JSch using the ARM variant of Java 8.

Using SSH works fine with the key:

pi@raspberrypi:~ $ ssh -i .ssh/Pi2Desktop2 -p 22 astump@
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-50-generic x86_64)

But when using the following Java code I eventually get an Auth Fail after it tries to connect for about 5 minutes:

public static Session getDesktopSession() throws JSchException {
    File keyfile = new File("/home/pi/.ssh/Pi2Desktop2");
    JunkyPrivate junkyPrivate = new JunkyPrivate();
    SSHVars sshVars = new SSHVars();
    Session session = null;
    JSch jsch = new JSch();
    System.out.println("JSCH trying: " + sshVars.getUser() + "@" + sshVars.getHostIP() + ":" + sshVars.getPort());
    session = jsch.getSession(sshVars.getUser(), sshVars.getHostIP(), sshVars.getPort());
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    config.put("HashKnownHosts", "yes");
    config.put("trust", "true");
    return session;

Returns this:

Raspberry Pi @Boot
Trying key @ /home/pi/.ssh/Pi2Desktop2
JSCH trying: astump@
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at com.jcraft.jsch.Session.connect(Session.java:183)
at asUtils.Pi.AtBoot.doAtBoot(AtBoot.java:31)
at asUtils.Pi.AtBoot.main(AtBoot.java:43)

This same exact code works fine on a Android phone running KitKat v4.4.

  • I don't think this has anything to do specifically with the raspberry pi. You may do better at stackoverflow.com. – Brick May 23 '19 at 20:34
  • I think it may because this same exact code works fine on a Android phone running KitKat v4.4 – user3260912 May 23 '19 at 21:51
  • Hmm. That was a potential important fact that I didn't see in the original post when I read it first time. Although it seems unlikely that the "same exact code" runs on Android since you've got a path hard-coded that looks specific to your Pi. – Brick May 24 '19 at 3:50
  • The only difference between the Android 4.4 and Raspberry Pi code is the fact the IP is the Internet facing IP and the key is the key specific for the Android phone. I tried changing the PI to go through the Internet to SSH but had no effect. – user3260912 May 25 '19 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.