title: JGit - ssh connectivity
body: <p>I am using JGit to connect to a remote Git repository. I tried below to perform same.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Main{
      public static void main(String args[]) throws Exception{
          JschConfigSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
                @Override
                protected void configure( Host host, Session session ) {
                  session.setPassword( "XXXX" );
                }
              };
  
              String REMOTE_URL="ssh://git@url/test.git";
              CloneCommand cloneCommand = Git.cloneRepository();
              cloneCommand.setURI( "ssh://git@url/test.git" );
              cloneCommand.setTransportConfigCallback( new TransportConfigCallback() {
                @Override
                public void configure( Transport transport ) {
                  SshTransport sshTransport = ( SshTransport )transport;
                  sshTransport.setSshSessionFactory( sshSessionFactory );
                }
              } );
  
              System.out.println("Listing remote repository " + REMOTE_URL);
              Collection&lt;Ref&gt; refs = Git.lsRemoteRepository()
                      .setHeads(true)
                      .setTags(true)
                      .setRemote(REMOTE_URL)
                      .call();
  
              for (Ref ref : refs) {
                  System.out.println("Ref: " + ref);
              }
      }
  }
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>Listing remote repository ssh://git@url/test.git
  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: ssh://git@url/test.git: UnknownHostKey: url. RSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
      at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:223)
      at org.eclipse.jgit.api.LsRemoteCommand.call(LsRemoteCommand.java:159)
      at Jgit.Jgit.Main.main(Main.java:94)
  Caused by: org.eclipse.jgit.errors.TransportException: ssh://git@url/test.git: UnknownHostKey: url. RSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
      at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:159)
      at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:136)
      at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.&lt;init&gt;(TransportGitSsh.java:262)
      at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:161)
      at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:202)
      ... 2 more
  Caused by: com.jcraft.jsch.JSchException: UnknownHostKey: ssh://git@url/test.git: UnknownHostKey: url. RSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
      at com.jcraft.jsch.Session.checkHost(Session.java:797)
      at com.jcraft.jsch.Session.connect(Session.java:342)
      at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
      ... 6 more
  </code></pre>
  
  <p>I looked over internet; and found that, below needs to be added:</p>
  
  <pre class="lang-java prettyprint-override"><code>com.jcraft.jsch.JSch.setConfig ( "StrictHostKeyChecking", "no" );
  </code></pre>
  
  <p>But, where to fit it in above code snippet. Is there any sample working code snippet available.</p>