title: Getting "com.jcraft.jsch.JSchException: Auth fail" – but "ssh" can login using public key authentication
body: <p>I am trying to connect a remote server using JSch but I am getting <em>&quot;Auth fail&quot;</em> exception. Below is my code:</p>
  <pre><code>String user = &quot;user.name&quot;;
  String host = &quot;hostip&quot;;
  try
  {
      JSch jsch = new JSch();
      Session session = jsch.getSession(user, host);
      session.setConfig(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;);
      System.out.println(&quot;Establishing Connection...&quot;);
      session.connect();
      int assinged_port=session.setPortForwardingL(lport, rhost, rport);
      System.out.println(&quot;localhost:&quot;+assinged_port+&quot; -&gt; &quot;+rhost+&quot;:&quot;+rport);
  }
  catch(Exception e){System.err.print(e);}
  </code></pre>
  <p>However when I try to ssh from iTerm using the command <code>ssh user.name@hostip</code> I can successfully access the remote server using public key authentication.</p>