Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGIT LS Remote Repositor using SSH(JGIT with SSH Keys)
JGIT LS Remote Repositor using SSH [message #1854208] Sat, 06 August 2022 18:39 Go to next message
Alfredo Espana is currently offline Alfredo EspanaFriend
Messages: 1
Registered: August 2022
Junior Member

I am working in an open source project that uses JGIT to get the tags from repositories in github, bitbucket, gitlab and azure devops using a personal access token and without authentication and it works really great.

Example Code:
public List<String> getVersions(RequestScope requestScope) {
        List<String> versionList = new ArrayList<>();
        try {
            CredentialsProvider credentialsProvider = null;
            if (vcs != null) {
      "vcs using {}", vcs.getVcsType());
                switch (vcs.getVcsType()) {
                    case GITHUB:
                        credentialsProvider = new UsernamePasswordCredentialsProvider(vcs.getAccessToken(), "");
                    case BITBUCKET:
                        credentialsProvider = new UsernamePasswordCredentialsProvider("x-token-auth", vcs.getAccessToken());
                    case GITLAB:
                        credentialsProvider = new UsernamePasswordCredentialsProvider("oauth2", vcs.getAccessToken());
                    case AZURE_DEVOPS:
                        credentialsProvider = new UsernamePasswordCredentialsProvider("dummy", vcs.getAccessToken());
                        credentialsProvider = null;
            Map<String, Ref> tags = Git.lsRemoteRepository()
            tags.forEach((key, value) -> {
                versionList.add(key.replace("refs/tags/", ""));
        } catch (GitAPIException e) {
        return versionList;

I would like to add support to use ssh key for my application using JGIT and Apache Mina.

I checked but I am getting "Unable to connect" with the following code:

        SshClient client = SshClient.setUpDefaultClient();
        try {
            GitSshdSessionFactory sshdFactory = new GitSshdSessionFactory(client);  // re-use the same client for all SSH sessions
            org.eclipse.jgit.transport.SshSessionFactory.setInstance(sshdFactory);  // replace the JSCH-based factory
        } finally {

I guess I am missing something but I am not really sure how to make the code work because I can't find examples and I am new using apache mina

Can someone guide me or maybe share some small example?
I would appreciate any help, thanks
Re: JGIT LS Remote Repositor using SSH [message #1854209 is a reply to message #1854208] Sat, 06 August 2022 20:19 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 521
Registered: August 2016
Senior Member
Don't know about the GitSshdSessionFactory from Apache MINA SSHD. Probably you have to configure the key to use somewhere. Also note that it is built against JGit 5.13. The current version of JGit is 6.2.

JGit has its own SSH support based on Apache MINA SSHD in bundle org.eclipse.jgit.ssh.apache. Example uses are in the test bundle available in the JGit repository, or a very simple setup is also in org.eclipse.jgit.pgm.TextBuiltin.execute().

Bundle org.eclipse.jgit.ssh.apache.agent adds support for SSH agents.
Previous Topic:Cherry pick a range of commit
Next Topic:Suddenly getting "No more authentication methods available" with ssh auth to git repo
Goto Forum:

Current Time: Thu Jun 01 09:05:06 GMT 2023

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

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

Back to the top