Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Connect to repo using SSH

Hey Roberto,

Thanks for your response. I am able to set the passphrase using the code below. Similarly, is it possible to set the ssh key as well? I do not want to use the default ssh file from the system as this is a user configurable property in my use case.

JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {

            @Override
            protected void configure(OpenSshConfig.Host hc, Session session) {
                CredentialsProvider provider = new CredentialsProvider() {
                    @Override
                    public boolean isInteractive() {
                        return false;
                    }

                    @Override
                    public boolean supports(CredentialItem... items) {
                        return true;
                    }

                    @Override
                    public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
                        for (CredentialItem item : items) {
                            ((CredentialItem.StringType) item).setValue(“password");
                        }
                        return true;
                    }
                };
                UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
                session.setUserInfo(userInfo);
            }
        };
        SshSessionFactory.setInstance(sessionFactory);

Cheers
Bhushan



On 03-Jun-2014, at 12:05 pm, Roberto Tyley <roberto.tyley@xxxxxxxxx> wrote:

The JSSH library used by JGit picks up SSH keys from ~/.ssh/ by default, IIRC. If you need more control you can fully configure this process with a TransportConfigCallback:

http://download.eclipse.org/jgit/docs/jgit-3.1.0.201310021548-r/apidocs/org/eclipse/jgit/api/TransportConfigCallback.html

For instance, if a client needs to replace the SshSessionFactorys on any SSHTransport used, they can set the TransportConfigCallback on the JGit API command - once the transport has been created by the command, the callback will be invoked and passed the transport instance, which the client can then inspect and configure as necessary.

Here's an example in Agit of using the callback to do custom SSH challenge generation - this may be slightly more involved than what you need, you can probably get away with one of the default JSSH Identity implementations:

https://github.com/rtyley/agit/blob/35c48634/agit/src/main/java/com/madgag/agit/git/AgitTransportConfig.java#L44-L46
https://github.com/rtyley/agit/blob/35c48634/agit/src/main/java/com/madgag/agit/ssh/AndroidSshSessionFactory.java
https://github.com/rtyley/agit/blob/35c48634/agit/src/main/java/com/madgag/ssh/authagent/client/jsch/SSHAgentIdentity.java




On 3 June 2014 07:21, Bhushan Nagaraj <bhushan154@xxxxxxxxx> wrote:
Hi all,

Using jgit API, how do I connect to a repository using a SSH key and passphrase?

Cheers
Bhushan
bhushan154@xxxxxxxxx



_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jgit-dev



Back to the top