小编Hou*_*ama的帖子

使用 JGit 的 SSH 身份验证来安全地访问 Git 存储库/身份验证失败

我在 scala 中使用 JGit 访问远程 Git 存储库,并且需要使用 SSH 进行身份验证。JGit 使用 JSch 提供安全访问。

我遵循了本教程:http://www.codeaffine.com/2014/12/09/jgit-authentication/

但是,我总是出现com.jcraft.jsch.JSchException:身份验证失败

我的方法是:

def sshCloneRemoteRepository() = {

// 1 / Override SSH configuration with JschConfigSessionFactory
val sshSessionFactory: SshSessionFactory  = new JschConfigSessionFactory() {

  override protected def createDefaultJSch(fs: FS): JSch = {
    val defaultJSch = super.createDefaultJSch(fs)
    defaultJSch.removeAllIdentity()
    defaultJSch.addIdentity(new File("/home/xw/.ssh/id_rsa").getAbsolutePath)
    defaultJSch.setKnownHosts("/home/xw/.ssh/known_hosts")
    val configRepository:ConfigRepository = com.jcraft.jsch.OpenSSHConfig.parseFile("/home/xw/.ssh/config")
    defaultJSch.setConfigRepository(configRepository)
    defaultJSch
  }

  override protected def configure(host:OpenSshConfig.Host, session:Session ) {
    // This still checks existing host keys and will disable "unsafe" authentication mechanisms
    // …
Run Code Online (Sandbox Code Playgroud)

git ssh scala jsch jgit

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

git ×1

jgit ×1

jsch ×1

scala ×1

ssh ×1