Repository navigation
can't clone use ssh key #866
Copy link
Copy link
Closed
Description
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 git@my.address.git ./code
stderr: 'Cloning into './code'...
git@gitlab.alipay-inc.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
haofrank commentedon May 6, 2019
chmod 400 ~/.ssh/id_rsawork's fine.