Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » SSHSessionFactory with Auth fail with token (SSHSessionFactory with Auth fail with token )
SSHSessionFactory with Auth fail with token [message #1854486] Sun, 21 August 2022 21:54 Go to next message
Eclipse UserFriend
I have the following code running and when I set the repo to the origin to HTTPS protocol I'm able to fetch using JGIT with no issues. However, when I change the repo's origin to an SSH protocol I get an AUTH failed error. I've looked through stack overflow and the documentation and am wondering if someone can take a look at this and advise on how to use a token to auth through SSH. Thanks

        FetchResult result = git.fetch().setTransportConfigCallback(transport -> {
            if (transport instanceof SshTransport) {
                SshTransport sshTransport = (SshTransport) transport;
                SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
                    @Override
                    protected void configure(OpenSshConfig.Host host, Session session) {
                        session.setPassword("<TOKEN>");
                        session.setConfig("StrictHostKeyChecking", "no");
                    }

                    @Override
                    protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
                        JSch jsch = super.getJSch(hc, fs);
                        jsch.removeAllIdentity();
                        return jsch;
                    }

                };
                sshTransport.setSshSessionFactory(sshSessionFactory);
            } else if (transport instanceof HttpTransport) {
                HttpTransport httpTransport = (HttpTransport) transport;
                httpTransport.setCredentialsProvider(new UsernamePasswordCredentialsProvider("<SERVICE_NAME", "<TOKEN>"));
            }
        }).setCheckFetchedObjects(true).call();
    }

[Updated on: Wed, 24 August 2022 16:23] by Moderator

Re: SSHSessionFactory with Auth fail with token [message #1854756 is a reply to message #1854486] Thu, 08 September 2022 01:24 Go to previous message
Eclipse UserFriend
AFAIK git servers in general do not allow password authentication with SSH. Use an SSH key pair.

Also check that you have the right user set. (For Github, it's "git", not the actual user name. For Gerrit, use the actual user ID.)

And please note that the SSH support in JGit based on JSch is no longer maintained. Consider moving to the SSH support based on Apache MINA sshd.
Previous Topic:RDi (Rational Developer Eclipse) using egit not finding git execs: bsh: git-receive-pack: not foun
Next Topic:Working Tree must not be numerical sorted
Goto Forum:
  


Current Time: Tue May 13 06:47:05 EDT 2025

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

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

Back to the top