2014-05-16 2 views
6

jt를 사용하여 지정된 ssh 키 파일 (~/.ssh /에없는 파일)을 사용하여 github에 어떻게 연결할 수 있는지 궁금합니다.jgit에 대한 ssh 키 지정

불행히도 JschConfigSessionFactory를 올바르게 사용하는 방법을 모르겠습니다.

org.eclipse.jgit.api.errors.TransportException: https://github.com/user/repo: not authorized 
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:160) 
    at gitio.GitInterface.pushToRemote(GitInterface.java:145) 
    at engine.GitInterfaceTester.main(GitInterfaceTester.java:25) 
Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/user/repo: not authorized 
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:479) 
    at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:396) 
    at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154) 
    at org.eclipse.jgit.transport.Transport.push(Transport.java:1173) 
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156) 
    ... 2 more 

내가 나타났습니다 :이 오류 (로그에서 생략 특정 저장소)를 얻을, 나는 전화 Using Keys with JGit to Access a Git Repository Securely

자식 그러나 git.push().setRemote(remotePath).call();를 사용하여 : 난 그냥이 문서의 것과 같은 설정을 만드는 시도했습니다 JschConfigSessionFactory에있는 사용자 정의 재정의 메소드가 실제로 호출되지 않는다는 것입니다. 이것은 거의 확실하게 문제의 원인입니다 ... 그러나 그들이 왜 호출되지 않았는지 모르겠습니다. 정의를 전달합니다 JschConfigSessionFactorySshSessionFactory을 사용하여 SshSessionFactory.setInstance(sessionFactory);

내가 뭘 잘못하고 있는지 아는 사람 있습니까?

+0

이 예제가 도움이됩니까 : 당신이이 글을 읽을 수 있습니다 JGit과 인증에 대한 자세한 내용은

? https://gist.github.com/quidryan/5449155 – VonC

답변

2

GitHub는 https URL에 암호 인증을 사용하고 SSH URL에 대해 공용 키 인증을 사용합니다 (https://gist.github.com/grawity/4392747 참조).

[email protected]ithub.com : user/repo.git와 같은 SSH URL에 대해서만 참조됩니다. https URL을 인증하려면 CredentialsProvider을 사용할 수 있습니다. 연결을 설정할 수있는 명령의 기본 클래스는 TransportCommand이며 setCredentialsProvider() 메서드를가집니다. PushCommand에 사용자 이름과 암호를 제공하는 CredentialsProvider을 지정하면 성공적으로 연결을 설정할 수 있습니다. http://www.codeaffine.com/2014/12/09/jgit-authentication/

+1

아, 알겠습니다. 잘못된 URL 스타일을 사용했습니다. [email protected] : user/repo.git이 근무했습니다. 고맙습니다! – nstbayless