Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Unable to connect using SSH in JGit(Unable to connect using SSH in JGit)
Unable to connect using SSH in JGit [message #1829533] Mon, 06 July 2020 05:31 Go to next message
Eclipse UserFriend
Hi,

I am trying to connect to github.com using SSH and JGit. This is the code I am trying:-
public static void gitClone(File gitDirectoryPath) throws Exception {
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setUserInfo(new UserInfo() {
@Override
public String getPassphrase() {
return "";
}

@Override
public String getPassword() {
return null;
}

@Override
public boolean promptPassword(String message) {
return false;
}

@Override
public boolean promptPassphrase(String message) {
return true;
}

@Override
public boolean promptYesNo(String message) {
return false;
}

@Override
public void showMessage(String message) {
}
});
}
};

Git.cloneRepository().setTransportConfigCallback(new SshTransportConfigCallback()).setURI("git@github.com:agarwalvipul/core-java-template.git")
.setDirectory(gitDirectoryPath).call();

}

private static class SshTransportConfigCallback implements TransportConfigCallback {
private final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
};

@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
}

I am getting the following exception:-
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: git@github.com:agarwalvipul/core-java-template.git: Auth fail
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:252)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
at com.lm.expertfees.Github.gitClone(Github.java:60)
at com.lm.expertfees.Test.main(Test.java:10)
Caused by: org.eclipse.jgit.errors.TransportException: git@github.com:agarwalvipul/core-java-template.git: Auth fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:182)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:137)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1269)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:241)
... 4 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:136)
... 11 more


Can anyone help me in this context?
Re: Unable to connect using SSH in JGit [message #1859065 is a reply to message #1829533] Wed, 10 May 2023 03:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi All,

I'm facing the same issue while trying to pull through SSH in jgit.
The key files are correct, double checked it.



SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
....


I'm setting this sessionFactory.


pull.setTransportConfigCallback(transport -> ((SshTransport)transport).setSshSessionFactory(sshSessionFactory));


Kindly advice how to proceed.
Re: Unable to connect using SSH in JGit [message #1859823 is a reply to message #1859065] Wed, 28 June 2023 15:27 Go to previous message
Eclipse UserFriend
We don't recommend the old jsch integration [1], use the integration for the mina-sshd client [2] instead.
You can start digging from JGit's unit tests for its integration with the mina-sshd client [3].

[1] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/refs/heads/master/org.eclipse.jgit.ssh.jsch/
[2] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/refs/heads/master/org.eclipse.jgit.ssh.apache/
[3] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/refs/heads/master/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java
Previous Topic:How to view the diff of a file between a local file change and a local HEAD in JGIT in a text form
Next Topic:Pull doesnt work in Git Perpective
Goto Forum:
  


Current Time: Mon May 19 11:30:19 EDT 2025

Powered by FUDForum. Page generated in 0.05027 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top