bash 一次性使用用户名密码身份验证的 Git 克隆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29728428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git clone with username password authentication in one go
提问by andrew
My current command is
我目前的命令是
git clone ssh://[email protected]/srv/git/repo
after that
在那之后
password
... fine, works good.
...很好,效果很好。
Now I would like do this in one line. Something like that:
现在我想在一行中做到这一点。类似的东西:
git clone ssh://username:[email protected]/srv/git/repo
but it`s not working and gives me the message:
但它不起作用,并给了我信息:
Please make sure you have the correct access rights and the repository exists.
How can I clone in a single line?
如何在一行中克隆?
回答by u1860929
You should be able to use the http
url instead to clone it:
您应该可以使用http
url 来克隆它:
git clone http://username:[email protected]/srv/git/repo.git
Edit:
编辑:
If in case you can do this by normal ssh only with username-password credentials, try using sshpass
like:
如果您只能使用用户名密码凭据通过普通 ssh 执行此操作,请尝试使用sshpass
:
sshpass -p password git clone ssh://[email protected]/srv/git/repo
You might have to install sshpass
for this.
您可能必须为此安装sshpass
。
Note that this is the case when the ssh keys are not correctly configured; if the ssh keys were configured, your public key would be shared with the target server and you wouldn't have needed to enter the password (you might have had to enter a passphrase though).
请注意,这是 ssh 密钥未正确配置的情况;如果配置了 ssh 密钥,您的公钥将与目标服务器共享,您就不需要输入密码(尽管您可能必须输入密码)。