我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
当前回答
1. 生成SSH密钥
Linux -麦克
打开终端创建ssh密钥:
cd ~ #Your home directory
ssh-keygen -t rsa #Press enter for all values
对于Windows
(只有当提交程序能够使用证书/私有和公共ssh密钥时才有效)
使用Putty Gen生成密钥 导出为打开的SSH密钥
下面是关于上述步骤的腻子生成的演练
2. 将SSH密钥与远程存储库关联
这一步不同,取决于遥控器的设置方式。
如果它是一个GitHub存储库,你有管理权限,进入设置并单击“添加SSH密钥”。复制~/.ssh/id_rsa的内容。pub到标记为“Key”的字段中。 如果您的存储库是由其他人管理的,请将您的id_rsa.pub交给管理员。 如果您的远程存储库由您的管理,您可以使用此命令,例如: scp ~ / . ssh / id_rsa。酒吧YOUR_USER@YOUR_IP: ~ / . ssh / authorized_keys / id_rsa . pub
3.将远程URL设置为支持SSH 1的表单
如果您已经执行了上述步骤,但仍然得到密码提示,请确保表单中有您的回购URL
git+ssh://git@github.com/username/reponame.git
而不是
https://github.com/username/reponame.git
要查看您的回购URL,运行:
git remote show origin
你可以用以下方法更改URL:
git remote set-url origin git+ssh://git@github.com/username/reponame.git
[1]本节结合了Eric P的答案
其他回答
在Windows操作系统上使用这个代替,这对我来说是有效的:
https://{Username}:{Password}@github.com/{Username}/{repo}.git
e.g.
git clone https://{Username}:{Password}@github.com/{Username}/{repo}.git
git pull https://{Username}:{Password}@github.com/{Username}/{repo}.git
git remote add origin https://{Username}:{Password}@github.com/{Username}/{repo}.git
git push origin master
只需使用——repo选项git push命令。是这样的:
$ git push --repo https://name:password@bitbucket.org/name/repo.git
1. 生成SSH密钥
Linux -麦克
打开终端创建ssh密钥:
cd ~ #Your home directory
ssh-keygen -t rsa #Press enter for all values
对于Windows
(只有当提交程序能够使用证书/私有和公共ssh密钥时才有效)
使用Putty Gen生成密钥 导出为打开的SSH密钥
下面是关于上述步骤的腻子生成的演练
2. 将SSH密钥与远程存储库关联
这一步不同,取决于遥控器的设置方式。
如果它是一个GitHub存储库,你有管理权限,进入设置并单击“添加SSH密钥”。复制~/.ssh/id_rsa的内容。pub到标记为“Key”的字段中。 如果您的存储库是由其他人管理的,请将您的id_rsa.pub交给管理员。 如果您的远程存储库由您的管理,您可以使用此命令,例如: scp ~ / . ssh / id_rsa。酒吧YOUR_USER@YOUR_IP: ~ / . ssh / authorized_keys / id_rsa . pub
3.将远程URL设置为支持SSH 1的表单
如果您已经执行了上述步骤,但仍然得到密码提示,请确保表单中有您的回购URL
git+ssh://git@github.com/username/reponame.git
而不是
https://github.com/username/reponame.git
要查看您的回购URL,运行:
git remote show origin
你可以用以下方法更改URL:
git remote set-url origin git+ssh://git@github.com/username/reponame.git
[1]本节结合了Eric P的答案
我使用的是https链接(https://github.com/org/repo.git) 而不是SSH链接;
git@github.com:org/repo.git
转换为我解决了这个问题!
这一切都是因为git在克隆/拉/推/取命令中没有提供通过管道发送凭证的选项。尽管它提供了证明。Helper,它存储在文件系统或创建一个守护进程等。通常,GIT的凭据是系统级的凭据,调用GIT命令的应用程序有责任保证它们的安全。非常不安全。
以下是我必须解决的问题。 1. Git版本(Git——version)应该大于或等于1.8.3。
吉特克隆
对于克隆,使用“git克隆URL”,将URL的格式从http://{myuser}@{my_repo_ip_address}/{myrepo_name.git}改为http://{myuser}:{mypwd}@{my_repo_ip_address}/{myrepo_name.git}
然后清除存储库中的密码,如下一节所示。
清除
现在,这个已经消失了
written the password in git remote origin. Type "git remote -v" to see the damage. Correct this by setting the remote origin URL without password. "git remote set_url origin http://{myuser}@{my_repo_ip_address}/{myrepo_name.git}" written the password in .git/logs in the repository. Replace all instances of pwd using a unix command like find .git/logs -exec sed -i 's/{my_url_with_pwd}//g' {} \; Here, {my_url_with_pwd} is the URL with password. Since the URL has forward slashes, it needs to be escaped by two backward slashes. For ex, for the URL http://kris:passs123@192.168.0.1/proj.git -> http:\\/\\/kris:passs123@192.168.0.1\\/proj.git
如果您的应用程序使用Java来发出这些命令,请使用ProcessBuilder而不是Runtime。如果必须使用Runtime,请使用getRunTime()。exec以字符串数组作为参数,以/bin/bash和-c作为参数,而不是以单个字符串作为参数。
GIT FETCH/PULL / PUSH
在git远程url中设置密码为:"git remote set_url origin http://{myuser}:{mypwd}@{my_repo_ip_address}/{myrepo_name.git}" 发出git fetch/push/pull命令。然后将不会提示您输入密码。 按照前一节的方法进行清理。不要错过。