Skip to content

Use custom ssh key cannot push/fetch/pull #690

Closed
@ghost

Description

Environment: GitPython (2.1.7), python 2.7.14, CentOS 6.9, git 2.15.0-rc1

I using this following code to clone:

ssh_key = os.path.join('.',Config.git.ssh_key)
ssh_key_command = 'ssh -i %s'%ssh_key
os.environ['GIT_SSH_COMMAND'] = 'ssh -i ./data/id_rsa'
repo = Repo.clone_from(Config.git.source,'wkdir')

It's work, but when I using:

r = Repo('wkdir')
with r.git.custom_environment(GIT_SSH_COMMAND='ssh -i ./data/id_rsa'):
	r.remotes.origin.fetch()

It say that:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 779, in fetch
    res = self._get_fetch_info_from_stderr(proc, progress)
  File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 665, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/usr/local/lib/python2.7/site-packages/git/cmd.py", line 418, in wait
    raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git fetch -v origin
  stderr: 'fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.'

I make sure I have full permission with remote repository, I also trying:

#!/bin/sh
ID_RSA=$PWD/data/hksd
exec /usr/bin/ssh -o StrictHostKeyChecking=no -i $ID_RSA "$@"

and

with r.git.custom_environment(GIT_SSH='id_rsa.sh'):
	r.remotes.origin.fetch()

It's doesn't work, too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions