Skip to content

Instantly share code, notes, and snippets.

@codeck
Created December 17, 2013 12:12
Show Gist options
  • Save codeck/8004013 to your computer and use it in GitHub Desktop.
Save codeck/8004013 to your computer and use it in GitHub Desktop.
call jgitenv.setup() before any jgit call
object jgitenv {
def setup() {
val jschConfigSessionFactory = new JschConfigSessionFactory() {
override def createDefaultJSch(fs:FS) = {
val jsch = new JSch();
try {
jsch.addIdentity("..\\id_rsa"); //_.pub must exist
jsch.setKnownHosts("..\\known_hosts");
} catch {
case e: JSchException => {
e.printStackTrace();
}
}
jsch
}
override def configure(host: OpenSshConfig.Host, session: Session) {
session.setConfig("StrictHostKeyChecking", "no");
//session.setConfig("IdentityFile", "..\\id_rsa")
session.setConfig("PreferredAuthentications", "publickey");
//session.setConfig("PreferredAuthentications", "gssapi-with-mic");
//session.setPassword("12345678")
}
}
SshSessionFactory.setInstance(jschConfigSessionFactory);
}
}