I'm using JGit to call a push command without using StrictHostKeyChecking
set to NO
, but I get the following error:
UnknownHostKey: <server hostname>. RSA key fingerprint is: <...>
The SSH key is set on the server, the known_hosts file contains the server hostname. I can do a push from the command line, but not from code.
Here's my code:
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory()
{
@Override
protected void configure(final OpenSshConfig.Host hc, Session session)
{
session.setPassword(passphrase);
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException
{
JSch jsch = super.createDefaultJSch(fs);
jsch.removeAllIdentity();
jsch.addIdentity("path to id_rsa");
jsch.setKnownHosts("path to known_hosts");
return jsch;
}
};
//SshSessionFactory.setInstance(sshSessionFactory);
TransportConfigCallback tcc = new TransportConfigCallback()
{
@Override
public void configure(Transport transport)
{
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
};
pushCommand.setTransportConfigCallback(tcc);
pushCommand.setPushTags().call();