无法使用相同的ssh键从脚本克隆git repo

时间:2019-06-25 06:24:26

标签: bash git ssh-keys

如果我在终端中手动输入以下命令:

cd ~
pwd
ssh-add -l
cd ~/Documents
git clone git@bitbucket.org:user/repo.git

我得到以下输出

/Users/ray
4096 SHA256:gwPuz8TpL0IRIp3k/DSsPqNEFrqZrXaeymSLspOIg41 /Users/ray/.ssh/id_rsa (RSA)
2048 SHA256:x0eBEFCwhfQ3K6VnM7C6w6dTV+l9TWFzRe5eJI3cYX1 /Users/ray/.ssh/id_rsa (RSA)
Cloning into 'repo'...
remote: Counting objects: 7316, done.
remote: Compressing objects: 100% (2232/2232), done.
remote: Total 7316 (delta 3420), reused 7242 (delta 3397)
Receiving objects: 100% (7316/7316), 826.72 KiB | 1.78 MiB/s, done.
Resolving deltas: 100% (3420/3420), done.

如果我随后将这些相同的行放入脚本中并运行它,我将获得相同的输出,但是如果另一个用户(根)运行了该脚本,则会得到以下输出:

/Users/ray
4096 SHA256:gwPuz8TpL0IRIp3k/DSsPqNEFrqZrXaeymSLspOIg41 /Users/ray/.ssh/id_rsa (RSA)
2048 SHA256:x0eBEFCwhfQ3K6VnM7C6w6dTV+l9TWFzRe5eJI3cYX1 /Users/ray/.ssh/id_rsa (RSA)
Cloning into 'repo'...
Unauthorized
fatal: Could not read from remote repository.

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

Git使用什么ssh密钥?还是有其他原因被拒绝?

编辑: 我还尝试过更改id_rsa文件的权限和所有权

编辑: 我可以通过致电sudo -H -u ray git clone...

来绕过此问题

0 个答案:

没有答案