1

I am trying to pull a repo from my Github account using GitPython. This is after

(1) I performed a git clone already from the command line.

(2) Generated new SSH keys using

ssh-keygen -t rsa -b 4096

(3) Setup the contents of the .pub file from #2 above in Github as a new SSH key.

I still get prompted to enter my Github username and password. Why is that ?

Here is the config in my .git folder. Note the http:// in the url instead of https://

[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

Here is my code snippet

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)
1
  • Did you chmod the private key?
    – Vetsin
    Commented May 14, 2017 at 3:45

1 Answer 1

3

Note the http:// in the url instead of https://4

As long as you are using an http(s) url, ssh won't come into play at all for authentication.

You need an ssh url:

[email protected]:USERNAME/OTHERREPOSITORY.git

An http url would still rely on the username/password authentication scheme.
Only an ssh url would use your public/private keys.

6
  • Changing to ssh url worked, however now I seem to get this error : cmdline: git pull -v origin master stderr: 'fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.' I can get over this by running these 2 in sequence - (1)ssh-agent -s (2)ssh-add ~/.ssh/id_rsa. However this doesn't seem to stick around e.g. few mins later (or new session) it complains about access permissions again until I run the same 2 commands. Commented May 14, 2017 at 15:49
  • @DancingJohn Is your private ssk key protected by a passphrase? You really don't need a passphrase for that: you could generate one without passphrase.
    – VonC
    Commented May 14, 2017 at 15:53
  • @DancingJohn But you need to have a private key protected by a passphrase, then help.github.com/articles/… is the reference. Make sure your agent is automatically launched, as described in help.github.com/articles/working-with-ssh-key-passphrases
    – VonC
    Commented May 14, 2017 at 15:54
  • No passphrase. Though my actual filename is github_id_rsa instead id_rsa. Hope that's not the issue. Commented May 14, 2017 at 16:48
  • @DancingJohn Then you don't need ssh_agent. But if your ssh key isn't named id_rsa, you will need to .ssh/config file: see for instance stackoverflow.com/a/22769324/6309
    – VonC
    Commented May 14, 2017 at 17:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.