2017-05-14 2 views
1

GitPython을 사용하여 Github 계정에서 repo를 가져 오려고합니다. 이것은 이후입니다GitPython + SSH 키를 사용하여 힘내 풀이 작동하지 않습니다.

(1) 명령 행에서 이미 git clone을 수행했습니다.

ssh-keygen -t rsa -b 4096 

(3) 설치 새로운 SSH 키로 Github에서의 상기 2 중에는 .pub 파일의 내용을 이용

(2) 생성 된 새로운 SSH 키.

여전히 내 Github 사용자 이름과 암호를 입력하라는 메시지가 표시됩니다. 왜 그런가요?

내 .git 폴더의 설정은 다음과 같습니다. 가 http 참고 : // 대신 HTTPS의 URL : //

여기
[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
[remote "origin"] 
    url = http://github.com/githubuser/myrepo.git 
    fetch = +refs/heads/*:refs/remotes/origin/* 
[branch "master"] 
    remote = origin 
    merge = refs/heads/master 

내 코드

import git, os 

DIR_NAME = 'path/to/dir/with/gitfolder' 
git_ssh_identity_file = os.path.expanduser('/path/to/rsa/key') 
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file 

with git.Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd): 

    repo = git.Repo.init(DIR_NAME) 
    origin = repo.remote() 
    refs = origin.refs 

    for ref in refs: 
     if ref.remote_head == "master": 
      origin.pull(ref.remote_head) 
+0

개인 키를 chmod 했습니까? – Vetsin

답변

1

참고을 http : // 대신 https://4

의 URL

http (s) url을 사용하는 한 ssh는 인증을 위해 전혀 작동하지 않습니다.

[email protected]:USERNAME/OTHERREPOSITORY.git 

HTTP URL을 여전히 사용자 명/패스워드 인증 방식에 의존하는 것 :

당신은 ssh를 URL이 필요합니다.
ssh URL 만 공개/개인 키를 사용합니다.

+0

ssh url로 변경하면 이제는이 오류가 발생합니다. cmdline : git pull -v origin master stderr : '치명적 : 원격 저장소에서 읽을 수 없습니다. 올바른 액세스 권한이 이고 저장소가 존재하는지 확인하십시오. ' 이것들을 순차적으로 실행함으로써이 문제를 해결할 수 있습니다 - (1) ssh-agent -s (2) ssh-add ~/.ssh/id_rsa. 그러나 이것은 예를 들어 주위에 머 무르지 않는 것처럼 보입니다. 나중에 몇 분 (또는 새 세션) 동일한 두 명령을 실행할 때까지 액세스 권한에 대해 다시 불평합니다. – DancingJohn

+0

@DancingJohn 개인 SSK 키가 암호로 보호되어 있습니까? 패스 프레이즈가 필요하지 않습니다. 패스 프레이즈없이 생성 할 수 있습니다. – VonC

+0

@DancingJohn하지만 암호로 보호 된 개인 키가 있어야합니다. https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh -agent/# add-ssh-key-to-the-ssh-agent가 참조입니다. https://help.github.com/articles/working-with-ssh-key-passphrases/ – VonC

관련 문제