如何避免每次git push时都指定用户名和密码? [英] How do I avoid the specification of the username and password at every git push?

查看:640
本文介绍了如何避免每次git push时都指定用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git push将我的工作保存到远程Git存储库.

I git push my work to a remote Git repository.

每个push都会提示我输入usernamepassword.我想在每次推送时都避免使用它,但是如何配置以避免它?

Every push will prompt me to input username and password. I would like to avoid it for every push, but how to configure to avoid it?

推荐答案

1.生成SSH密钥

Linux/Mac

打开终端以创建ssh密钥:

1. Generate an SSH key

Linux/Mac

Open terminal to create ssh keys:

cd ~                 #Your home directory
ssh-keygen -t rsa    #Press enter for all values

对于Windows

(仅在提交程序能够使用证书/专用和公共ssh密钥的情况下有效)

For Windows

(Only works if the commit program is capable of using certificates/private & public ssh keys)

  1. 使用Putty Gen生成密钥
  2. 将密钥导出为开放的SSH密钥

这是腻子gen的演练

此步骤会有所不同,具体取决于您的遥控器的设置方式.

This step varies, depending on how your remote is set up.

  • 如果它是GitHub存储库,并且您具有管理权限,请转到 设置 ,然后单击添加SSH密钥".将~/.ssh/id_rsa.pub的内容复制到标有密钥"的字段中.

  • If it is a GitHub repository and you have administrative privileges, go to settings and click 'add SSH key'. Copy the contents of your ~/.ssh/id_rsa.pub into the field labeled 'Key'.

如果您的存储库由其他人管理,请给管理员您的id_rsa.pub.

If your repository is administered by somebody else, give the administrator your id_rsa.pub.

如果您的远程存储库是由您管理的,则可以使用以下命令,例如:

If your remote repository is administered by your, you can use this command for example:

scp ~/.ssh/id_rsa.pub YOUR_USER@YOUR_IP:~/.ssh/authorized_keys/id_rsa.pub

如果您已完成上述步骤,但仍收到密码提示,请确保您的回购URL格式为

If you have done the steps above and are still getting the password prompt, make sure your repo URL is in the form

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

相对于

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

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

To see your repo URL, run:

git remote show origin

您可以使用以下方式更改网址:

You can change the URL with:

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

[1]本部分结合了 Eric P

这篇关于如何避免每次git push时都指定用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆