jgit 指定ssh key 的保存路径
SShSessionFactory.java
import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig;
import org.eclipse.jgit.transport.OpenSshConfig.Host;
import org.eclipse.jgit.util.FS;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
public class MySShSessionFactory extends JschConfigSessionFactory {
private String sshKeyFilePath;
@Override
protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
JSch jsch = new JSch();
jsch.removeAllIdentity();
jsch.addIdentity(sshKeyFilePath);
jsch.setKnownHosts("C:\\known_hosts");
return jsch;
}
@Override
protected void configure(Host hc, Session session) {
TODO Auto-generated method stub
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
}
public String getSshKeyFilePath() {
return sshKeyFilePath;
}
public void setSshKeyFilePath(String sshKeyFilePath) {
this.sshKeyFilePath = sshKeyFilePath;
}
}
Martin 于 4月24日
jgitssh-key 0 0