Git推送:用户名,密码,如何避免? [英] Git push: username, password, how to avoid?

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

问题描述



每一个推送(push) 会提示我输入用户名密码。我想避免每次推送,但如何配置,以避免它? 解决方案

生成SSH密钥



Linux / Mac



打开终端以创建ssh密钥:

  cd〜#您的主目录
ssh-keygen -t rsa#按所有值的输入



对于Windows



(仅在提交程序能够使用证书/私有& public ssh keys)


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

以下是演练上面的步骤腻子gen

2。将SSH密钥与远程存储库相关联



这一步有所不同,具体取决于远程设置。




  • 如果它是GitHub存储库并且您拥有管理权限,请转至 设置 ,然后点击添加SSH密钥。将您的〜/ .ssh / id_rsa.pub 的内容复制到标记为'Key'的字段中。


  • 如果您的存储库由其他人管理,请为管理员提供您的 id_rsa.pub


  • 如果您的远程存储库由您管理,则可以使用以下命令:
    $ b scp〜/ .ssh / id_rsa.pub YOUR_USER @ YOUR_IP :〜/ .ssh / authorized_keys / id_rsa.pub




3。将您的远程URL设置为支持SSH的表单 1



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

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

相对于

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

查看您的回购URL,运行:

  git远程显示来源

您可以更改URL:

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

[1]本节包含 Eric P 的答案


I git push my work to a remote Git repository.

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. 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

For Windows

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

  1. Use Putty Gen to generate a key
  2. Export the key as an open SSH key

Here is a walkthrough on putty gen for the above steps

2. Associate the SSH key with the remote repository

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

  • 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'.

  • 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

3. Set your remote URL to a form that supports SSH 1

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

as opposed to

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

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] This section incorporates the answer from Eric P

这篇关于Git推送:用户名,密码,如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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