我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
当前回答
我建议使用凭证管理器来存储GitHub凭证。使用git config——global credential。助手存储是不安全的,因为它以明文存储GitHub密码。 对于Linux, libsecret是一个很好的替代方案。对于Ubuntu和其他一些linux发行版,您可以执行以下操作:
安装:
sudo apt-get update
sudo apt install libsecret-1-0 libsecret-1-dev
sudo apt install gnome-keyring
创建
cd /usr/share/doc/git/contrib/credential/libsecret/
Sudo make
配置git使用libsecret存储密码
git config --global credentail.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
在此设置后输入一次密码后,git凭据将由libsecret存储。
其他回答
只是想指出上面说过几次的解决方案:
git config credential.helper store
在此之后,您可以使用任何需要密码的命令。你不需要用力。之后,你就不需要再输入你的用户名/密码了。
我用了帕维尔建议的答案,它对我很有效。我的区别是这样做,而我是这样添加远程:git远程添加(别名)https://(name:password)@github.com/(the远程地址).git
使用Git存储库进行永久身份验证,
运行以下命令启用凭据缓存。
$ git config credential.helper store
$ git push https://github.com/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
Use还应该指定缓存过期,
git config --global credential.helper 'cache --timeout 7200'
启用凭据缓存后,它将被缓存7200秒(2小时)。
注意:凭据帮助程序将未加密的密码存储在本地磁盘上。
看起来,至少在Windows上使用TortoiseGIT时,可以创建SSH密钥并将其传输到GIT服务器,只需使用:
> ssh-keygen.exe
> ssh-copy-id [username]@[GIT_server]
无限期保存
您可以使用git-credential-store
git config credential.helper store
在文件系统中保存未加密的密码:
使用此助手将在磁盘上存储未加密的密码,仅受文件系统权限的保护。如果这不是一种可以接受的安全折衷,请尝试git-凭据-缓存,或寻找与操作系统提供的安全存储集成的帮助器。
使用暂停
使用git-credential-cache,默认保存密码15分钟。
git config credential.helper cache
要设置不同的超时,使用——timeout(这里是5分钟)
git config credential.helper 'cache --timeout=300'
安全无限保存(OS X和Windows)
If you’re using a Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. This method stores the credentials on disk, and they never expire, but they’re encrypted with the same system that stores HTTPS certificates and Safari auto-fills. Running the following on the command line will enable this feature: git config --global credential.helper osxkeychain. You'll need to store the credentials in the Keychain using the Keychain app as well. If you’re using Windows, you can install a helper called “Git Credential Manager for Windows.” This is similar to the “osxkeychain” helper described above, but uses the Windows Credential Store to control sensitive information. It can be found at https://github.com/Microsoft/Git-Credential-Manager-for-Windows. [emphases mine]