有没有办法跳过密码输入使用https时:// GitHub上? [英] Is there a way to skip password typing when using https:// on GitHub?

查看:407
本文介绍了有没有办法跳过密码输入使用https时:// GitHub上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我切换到同步我的仓库到https:// GitHub上(由于防火墙问题),而且每次都要求输入密码。它曾经是,我有一个 SSH 证书,这就足够了。有没有一种方法可以绕过我的情况下,密码(使用HTTP / HTTPS)?

I recently switched to synchronising my repositories to https:// on GitHub (due to firewall issues) and it asks for a password every time. It used to be that I had an SSH certificate, and it was enough. Is there a way to bypass the password in my case (using http/https)?

推荐答案

由于Git的1.7.9(2012年1月下旬发布),有在Git中是一个整洁的机制,以避免输入密码所有HTTP / HTTPS的时候,所谓的credential助手的。 (感谢您指出在下面的评论这项新功能dazonic 。)

With Git version 1.7.9 and later

Since Git 1.7.9 (released in late January 2012), there is a neat mechanism in Git to avoid having to type your password all the time for HTTP / HTTPS, called credential helpers. (Thanks to dazonic for pointing out this new feature in the comments below.)

使用Git的1.7.9或更高版本,你可以使用以下凭据助手之一:

With Git 1.7.9 or later, you can just use one of the following credential helpers:

git config --global credential.helper cache

...它告诉Git的在内存中保存的密码缓存(默认情况下)15分钟。可以set用更长的超时

git config --global credential.helper "cache --timeout=3600"

(这个例子建议在Linux的的 GitHub的帮助页面。)您还可以存储您的凭据永久如果需要的话,请参见下面的答案。

(That example was suggested in the GitHub help page for Linux.) You can also store your credentials permanently if so desired, see the other answers below.

GitHub的帮助也表明,如果​​你在Mac OS X和使用自制,以便安装Git,那么可以使用本机的Mac OS X与密钥库:

GitHub's help also suggests that if you're on Mac OS X and used Homebrew to install Git, you can use the native Mac OS X keystore with:

git config --global credential.helper osxkeychain

有关Windows中,有一个叫帮手 Git的凭据管理器为Windows 或<一个href=\"https://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command\">wincred在msysgit 。

For Windows, there is a helper called Git Credential Manager for Windows or wincred in msysgit.

git config --global credential.helper wincred

对于Linux,你可以使用 GNOME -keyring (或其他钥匙圈的实施,如KDE钱包)。

For Linux, you can use gnome-keyring(or other keyring implementation such as KWallet).

使用1.7.9之前的Git版本中,这更安全的选项不可用,你就需要改变你的原产地遥控器使用,以包括网址密码以这种方式:

With versions of Git before 1.7.9, this more secure option is not available, and you'll need to change the URL that your origin remote uses to include the password in this fashion:

https://you:password@github.com/you/example.git

......与换言之:密码后的用户名和前<​​code> @

您可以设置一个新的URL为你的原产地远程使用:

You can set a new URL for your origin remote with:

git config remote.origin.url https://you:password@github.com/you/example.git

请确保您使用 HTTPS ,你应该知道,如果你这样做,你的GitHub的密码将被存储在纯文本在。混帐目录中,这显然是不可取的。

Make sure that you use https and you should be aware that if you do this, your GitHub password will be stored in plaintext in your .git directory, which is obviously undesirable.

另一种方法是把你的用户名和密码在你的〜/的.netrc 文件,虽然,与远程URL保存密码,这意味着你的密码将被存储在磁盘上以纯文本格式,因此安全性较低,不推荐。但是,如果你想要采取这种方法,下面一行添加到您的〜/的.netrc

An alternative approach is to put your username and password in your ~/.netrc file, although, as with keeping the password in the remote URL, this means that your password will be stored on the disk in plain text and is thus less secure and not recommended. However, if you want to take this approach, add the following line to your ~/.netrc:

machine <hostname> login <username> password <password>

...替换&LT;主机名&GT; 与服务器的主机名,&lt;用户名&GT; &LT;密码和GT; 与您的用户名和密码。还记得在那个文件上设置限制文件系统权限:

... replacing <hostname> with the server's hostname, and <username> and <password> with your username and password. Also remember to set restrictive file system permissions on that file:

chmod 600 ~/.netrc

请注意,在Windows上,该文件应该叫做 _netrc ,你可能需要定义%HOME%环境变量 - 详细内容见:

Note that on Windows, this file should be called _netrc, and you may need to define the %HOME% environment variable - for more details see:

这篇关于有没有办法跳过密码输入使用https时:// GitHub上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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