3

I'm trying to clone a project from git using Python's Gitpython library, but instead of password i want to use ssh keys for authentication. I've created a pair of private and public keys and put the public in git and the private in the project directory. In my code i'm using the following commands:

My import:

from git import Repo

The clone command:

ssh_cmd = 'ssh -i private_key.ppk'
Repo.clone_from(GIT_USERS_URL, local_git_dir, env={'GIT_SSH_COMMAND': ssh_cmd})

'private_key.ppk' is the name of the private key file.

When running the script i get the following error:

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I know this question has been asked a lot but none of the solutions worked and i don't see why ?

I also run the following commands before i reach the clone statement:

git_process = git.Git(**path to folder to be pushed later on to git**)
git_process.update_environment(SSH_KEY=SSH_PRIVATE_KEY)

Where SSH_PRIVATE_KEY is the path to the private key.

What am i missing ?

Thanks !

Caffeine
  • 445
  • 1
  • 4
  • 16
  • Your ssh command is failing. I feel like this more of a ssh problem than an actual GitPython library one. – scharette Jul 18 '18 at 14:21
  • Is there a solution ? It seems like the only option is to use subprocess library and run it in the cmd but my intention is to be OS-independent. – Caffeine Jul 18 '18 at 14:25
  • Can you connect to the server with ssh and this private key but without git? It could be [wrong key format](https://stackoverflow.com/q/2224066/7976758). – phd Jul 18 '18 at 18:27
  • Try the cli command in bash. GIT_SSH_COMMAND="ssh -i /home/user/test_private_key" git clone ssh://git@git_domain:1399/project/repo.git /home/user/git_download -v If this fails, then its an issue with your ssh authentication. – ozn Jan 24 '19 at 04:34

0 Answers0