1. 通過ssh密鑰實現
ssh-keygen -t rsa -C "你的郵箱" -f "自己定義的目錄"
打開: id_rsa.pub ,將文件內容復制到 gitlab 設置頁:ssh密鑰配置。
2. 通過配置.git-credential配置免密輸入
可以進行設置,這樣在輸入過一次密碼之后,以后就不需要每次都輸入密碼了。
打開終端:
輸入:
touch ~/.git-credentials
如果手工在其中加入:
https:{username}:{password}@***.com
那么第一次訪問git地址,也不用輸入密碼了。
再輸入:
git config --global credential.helper store
這一步會在用戶目錄下的.gitconfig文件最后添加:
[credential]
helper = store
3. git 版本原因git clone 無法輸入密碼問題
git出現error: The requested URL returned error: 401 Unauthorized while accessing得到原因是因為服務器的git版本是 git version 1.7.1
- 可以使用如下操作:
git clone https://username:password@url/project.git
如果這樣設置,下次密碼變更時,需要重定向git倉庫地址:
git remote set-url origin url #同樣需要再url中定義賬號和密碼
4. 其他:清除記住的用戶、密碼
git config --system --unset credential.helper