我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
当前回答
你必须设置一个SSH私钥,你可以看看这个页面,如何在Mac上进行设置,如果你在linux上,指南应该是差不多的,在Windows上你需要像MSYS这样的工具。
其他回答
无限期保存
您可以使用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]
我建议使用凭证管理器来存储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存储。
你必须设置一个SSH私钥,你可以看看这个页面,如何在Mac上进行设置,如果你在linux上,指南应该是差不多的,在Windows上你需要像MSYS这样的工具。
看起来,至少在Windows上使用TortoiseGIT时,可以创建SSH密钥并将其传输到GIT服务器,只需使用:
> ssh-keygen.exe
> ssh-copy-id [username]@[GIT_server]
第一步-
使用以下命令在linux系统上创建SSH密钥
ssh-keygen -t rsa -b 4096 -C "your_email"
它将询问密码短语和文件名(默认为~/)。ssh / id_rsa ~ / . ssh / id_rsa . pub)
步骤2 -
一旦文件创建,添加公钥id_rsa。Pub到github帐户SSH部分。
第三步-
在您的机器上,使用以下命令将私钥id_rsa添加到ssh-agent
ssh-add ~/.ssh/id_rsa
步骤4 -
现在使用以下命令将远程url git@github.com:user_name/repo_name.git添加到本地git repo中。
git remote remove origin
git remote add origin git@github.com:user_name/repo_name.git
这是它。