I am using JGit in Java and have the following code:
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure( Host host, Session session ) {
session.setPassword( "password" );
}
} );
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI( "ssh://user@example.com/repo.git" );
cloneCommand.setTransportConfigCallback( new TransportConfigCallback() {
@Override
public void configure( Transport transport ) {
SshTransport sshTransport = ( SshTransport )transport;
sshTransport.setSshSessionFactory( sshSessionFactory );
}
} );
I was trying to clone a repository, which is secured with SSH. I would like to force JGit to use my credentials, like username and password.
In my case, JGit internally checks my system environments and finding my .ssh
folder, where the public key is stored and uses it to authenticate.
So, there is no need to use credentials like password and username. But, I want to force JGit to use credentials and not checking my environment variables and finding my public key.
Is there a way, to clone an ssh-repository and force JGit to use my credentials instead of the public key?