一次性使用用户名密码认证进行Git克隆

8

我的当前命令是:

git clone ssh://username@onboard.com/srv/git/repo

之后
password

...很好,运行良好。

现在我想用一行代码实现这个功能。就像这样:

git clone ssh://username:password@onboard.com/srv/git/repo

但它无法工作,会给我以下信息:

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

如何在一行代码中进行克隆?


你是否尝试使用HTTP? - Akash Shinde
1个回答

20

您应该能够使用http URL来克隆它:

git clone http://username:password@onboard.com/srv/git/repo.git

编辑:

如果您可以使用用户名和密码凭据通过常规ssh执行此操作,请尝试使用sshpass

sshpass -p password git clone ssh://username@onboard.com/srv/git/repo

你可能需要安装sshpass

请注意,这种情况通常发生在ssh密钥配置错误的情况下;如果正确配置了ssh密钥,你的公钥将与目标服务器共享,你就不需要输入密码(但你可能需要输入口令)。


非法的:这是一个git仓库吗?我必须使用ssh完成此操作。 - andrew
1
你是通过SSH密钥访问还是通过普通的用户名密码进行SSH身份验证?如果是前者,那么可以不需要密码进行访问,但如果是后者,你可以尝试使用sshpass(虽然我不确定确切的命令)。尝试类似于sshpass -p password git clone ssh://username@onboard.com/srv/git/repo这样的命令。 - Anshul Goyal
需要安装sshpass包。这不是问题。 - andrew
请注意,HTTP、用户名或密码中的特殊字符需要进行编码。使用此工具对其进行编码:http://meyerweb.com/eric/tools/dencoder/ - vikas027
@mu無 在使用 git clone http://username:password@onboard.com/srv/git/repo.git 克隆后,如何使用自己的用户名和密码将其推送到远程仓库? - Nam Vu
当使用sshpass时,您可能还需要使用-P "Enter passphrase for key '/home/whatever_user/.ssh/id_rsa':" 。它适用于使用SSH进行克隆以及拉取和推送。太棒了;) - alexandre1985

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接