git 免密操作,包括 ssh 和 https
ssh
使用 ssh 协议,需要注册公钥到 git 服务器,不再赘述
https
使用 credential.helper
- 执行
git config --global credential.helper store - 执行
touch ~/.git-credentials,添加如下内容https://{username}:{password}@github.com
这个方式存在一个缺点, username 和 password 明文保存
可以使用如下设置保存到 cache 来增加安全性
git config --global credential.helper 'cache --timeout=3600'
另外,可以使用命令将协议从 https 切换到 ssh
git remote set-url origin git@github.com:yourusername/yourrepositoryname.git
加密存储
** git 也提供了加密存储,可以稍稍增加安全性**
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
- 删除
.git-credentials git pull,输入username和password- 密文保存