我正在使用 jgit 安全地访问 GitHub 中的存储库。我执行以下操作来生成用于 GitHub 和我的客户端代码之间安全通信的密钥。
生成密钥对:
ssh-keygen -t rsa
使用 Account Settings -> SSH keys -> add SSH key 将公钥添加到 GitHub 帐户
将步骤 1 中生成的私钥添加到本地主机:
ssh-add id_rsa
执行此操作后,当我尝试访问 GitHub 并进行克隆时,仍然收到以下错误:
org.eclipse.jgit.api.errors.TransportException: git@github.com:test/test_repo.git: UnknownHostKey: github.com. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:137)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
这是我使用的代码:
String localPath, remotePath;
Repository localRepo;
Git git;
localPath = <path_to_local_repository>;
remotePath = "git@github.com:test/test_repo.git";
try {
localRepo = new FileRepository(localPath + "/.git");
} catch (IOException e) {
e.printStackTrace();
}
git = new Git(localRepo);
CloneCommand cloneCmd = git.cloneRepository().
setURI(remotePath).
setDirectory(new File(localPath));
try {
cloneCmd.call();
} catch (GitAPIException e) {
log.error("git clone operation failed");
e.printStackTrace();
}
请让我知道这里的问题以及我应该怎么做才能纠正它。
谢谢。