1

I've got some code which needs to grab code from github periodically (on a Windows machine).

When I do pulls manually, I use GitBash, and I've got ssh keys running for the repos I check so everything is fine. However when I try to run the same actions in a python subprocess I don't have the ssh services which GitBash provides and I'm unable to authenticate to the repo.

How should I proceed from here. I can think of a couple of different options:

  1. I could revert to using https:// fetches. This is problematic because the repos I'm fetching use 2-factor authentication and are going to be running unattended. Is there a way to access an https repo that has 2fa from a command line?

  2. I've tried calling sh.exe with arguments that will fire off ssh-agent and then issuing my commands so that everything is running more or less the way it does in gitBash, but that doesn't seem to work:

    "C:\Program Files (x86)\Git\bin\sh.exe" -c "C:/Program\ Files\ \(x86\)/Git/bin/ssh-agent.exe; C:/Program\ Files\ \(x86\)/Git/bin/ssh.exe -t [email protected]"
    

    produces

    SSH_AUTH_SOCK=/tmp/ssh-SiVYsy3660/agent.3660; export SSH_AUTH_SOCK;
    SSH_AGENT_PID=8292; export SSH_AGENT_PID;
    echo Agent pid 8292;
    Could not create directory '/.ssh'.
    The authenticity of host 'github.com (192.30.252.129)' can't be established.
    RSA key fingerprint is XXXXXXXXXXX
    Are you sure you want to continue connecting (yes/no)? yes
    Failed to add the host to the list of known hosts (/.ssh/known_hosts).
    Permission denied (publickey).
    
  3. Could I use an ssh module in python like paramiko to establish a connection? It looks to me like that's only for ssh'ing into a remote terminal. Is there a way to make it provide an ssh connection that git.exe can use?

So, I'd be grateful if anybody has done this before or has a better alternative

asked Oct 2, 2014 at 6:17

1 Answer 1

1

The git bash set the HOME environment variable, which allows git to find the ssh keys (in %HOME%/.ssh)

You need to make sure the python process has or define HOME to the same PATH.
As explained in "Python os.environ["HOME"] works on idle but not in a script", you need to set HOME to %USERPROFILE% (or, in python, to os.path.expanduser("~") ).

answered Oct 2, 2014 at 6:32
Sign up to request clarification or add additional context in comments.

1 Comment

That did it, thanks! Setting the HOME variable correctly got it running

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.