我把我的工作推到一个远程git存储库。

每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?


当前回答

如果您已经设置了SSH密钥,并且仍然得到密码提示,请确保表单中有您的回购URL

git+ssh://git@github.com/username/reponame.git

而不是

https://github.com/username/reponame.git

要查看您的回购URL,运行:

git remote show origin

你可以像这样用git remote set-url修改URL:

git remote set-url origin git+ssh://git@github.com/username/reponame.git

其他回答

运行下面的命令为我解决了这个问题。

git config --global credential.helper wincred

请参考以下github文档:

https://help.github.com/articles/caching-your-github-password-in-git/

将git客户端连接到操作系统凭据存储。例如,在Windows中,您将凭据帮助器绑定到wincred:

git config --global credential.helper wincred

在GitHub上使用https://时是否有办法跳过密码输入?

据我所知,只有两种安全的方法:使用密钥库加密的ssh或passwd。

SSH

Log in your github; Visit: https://github.com/settings/keys; New SSH key; cat ~/.ssh/id_rsa.pub, paste it there, name and save it (if you have no such file, generate one for yourself by ssh-keygen -t rsa - just Enter for all prompts); Go to your local repository and update your remote by git remote set-url origin git+ssh://git@github.com/username/reponame.git - you can check it first by git remote -v); Here you go, just touch t; git add t; git commit -m "test"; git push and confirm yes to enjoy the password-free world.

passwd使用密钥库加密

如果你只使用git config -global credential。如其他人所述,您未加密的密码将以纯文本形式存储在~/下。git证书听起来并不安全。

尝试将其加密为

sudo apt-get install libgnome-keyring-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring

git config --global credential.helper store

在本例中,您使用https://git@github.com/username/reponame.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的答案

你必须设置一个SSH私钥,你可以看看这个页面,如何在Mac上进行设置,如果你在linux上,指南应该是差不多的,在Windows上你需要像MSYS这样的工具。