Skip to content

can't clone use ssh key #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
haofrank opened this issue Apr 29, 2019 · 1 comment
Closed

can't clone use ssh key #866

haofrank opened this issue Apr 29, 2019 · 1 comment

Comments

@haofrank
Copy link

hi~ I can't use my id_rsa key to clone my repo.
this is my directory structure:

├── code
├── git_test.py
├── id_rsa
├── id_rsa.pub
└── ssh_executable.sh

git_test.py

import os
import git
from git import Repo
from git import Git

git_url = "git@xxx/xxx.git"
git_branch = "master"
out_dir = "./code"

# One
git_ssh_identity_file = os.path.expanduser('./id_rsa')
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file

with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
  repo = Repo.clone_from(git_url, out_dir, branch="master")
  print("Success")

# Two
ssh_executable = os.path.join("./", 'ssh_executable.sh')

with Git().custom_environment(GIT_SSH=ssh_executable):
  repo = Repo.clone_from(git_url, out_dir, branch="master")
  print("Success")

ssh_executable.sh

#!/bin/sh
ID_RSA="./id_rsa"
exec /usr/bin/ssh -o StrictHostKeyChecking=no -i $ID_RSA "$@"

I tried both methods and could not succeed clone repo....
if I move the id_res id_res.pub to ~/.ssh. it will success. hoping to get your help~

Traceback (most recent call last):
  File "git_test.py", line 15, in <module>
    repo = Repo.clone_from(git_url, out_dir, branch="master")
  File "/Users/frank/miniconda3/lib/python3.7/site-packages/git/repo/base.py", line 988, in clone_from
    return cls._clone(git, url, to_path, GitCmdObjectDB, progress, **kwargs)
  File "/Users/frank/miniconda3/lib/python3.7/site-packages/git/repo/base.py", line 939, in _clone
    finalize_process(proc, stderr=stderr)
  File "/Users/frank/miniconda3/lib/python3.7/site-packages/git/util.py", line 333, in finalize_process
    proc.wait(**kwargs)
  File "/Users/frank/miniconda3/lib/python3.7/site-packages/git/cmd.py", line 415, in wait
    raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git clone --branch=master -v [email protected] ./code
  stderr: 'Cloning into './code'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
@haofrank
Copy link
Author

haofrank commented May 6, 2019

chmod 400 ~/.ssh/id_rsa
work's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant