通过bash脚本进行Git Clone SSH身份验证 [英] Git Clone ssh authentication through bash script
问题描述
我正在使用Raspbian.
I'm using Raspbian.
我确实成功添加了密钥,并且可以使用命令git clone git@github.com:USER/repo.git
使用ssh auth手动克隆私有存储库.
I did successfully added the key and I can clone a private repo with ssh auth manually, using the command git clone git@github.com:USER/repo.git
.
这是我的设置方式:
ssh-keygen -t rsa -b 4096 -C "email"
eval "$(ssh-agent -s)"
ssh-add -k ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
但是,如果我尝试通过bash脚本运行git clone命令,则会得到Permission denied (publickey).
However, if I try to run git clone command through a bash script, I get Permission denied (publickey).
我使用sudo将脚本运行为"pi".脚本以#! /bin/bash
开头,而whoami
(在脚本上)返回root
,而不是"pi".
I'm running the script as "pi", with sudo. The script starts with #! /bin/bash
and whoami
(on the script) returns root
, instead of "pi".
有人可以帮我吗?
谢谢!
推荐答案
SSH尝试从$HOME/.ssh
中读取密钥.由于您以root
身份运行,因此该脚本很可能无法在/home/root/.ssh
下找到任何内容.
SSH attemps to read the keys from $HOME/.ssh
. Since you are running as root
, the script most likely fails to find anything under /home/root/.ssh
.
解决办法?尝试sudo -E
,它保留了环境变量.有关更多信息,请参考 sudo(8).
The fix? Try sudo -E
, which preserves the environment variables. For more info, consult sudo(8).
这篇关于通过bash脚本进行Git Clone SSH身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!