[英]Disable osxkeychain credential helper in git as installed by Xcode
[英]How to disable osxkeychain as credential helper in git config?
我需要禁用 OS X 的憑據助手: git credential-osxkeychain
它在全局配置文件和本地配置文件中都被禁用,實際上它從未被啟用。 盡管如此,它仍然會記住我的 github 登錄詳細信息。
我在筆記本電腦上,所以我不希望自動無密碼訪問我的存儲庫。
我將使用 ssh 密鑰。 這是一台新計算機,整個系統設置仍在進行中。
現在我使用了https
repo refs,並且憑證助手不斷發揮作用。
這些是我的 conf 文件:
git config --edit
=>
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = https://github.com/user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "develop"]
remote = origin
merge = refs/heads/develop
[branch "deploy"]
remote = origin
merge = refs/heads/deploy
git config --global --edit
=>
[user]
email = ****************
name = tom
[color]
ui = true
[core]
editor = subl -w
[github]
user = tompave
[merge]
conflictstyle = diff3
[push]
default = simple
此外,運行git config --global credential.helper
不會返回任何內容(沒錯)。
但是,運行git config credential.helper
會返回osxkeychain
!
這怎么可能? 我在本地配置文件中看不到它,它在哪里設置?
我嘗試在本地設置它以查看會發生什么,它確實出現在repodir/.git/config
中。 然后我刪除了該條目......但助手仍然在這里並且處於活動狀態。
我可以清楚地看到它在 OS X 鑰匙串中的條目。
我可以刪除它,然后git會再次要求輸入密碼......但是只要我輸入它(比如說,對於git fetch
),鑰匙串中的條目就會恢復。
為了幫助追蹤設置,我會嘗試使用:
git config --local credential.helper
git config --global credential.helper
git config --system credential.helper
第一個檢查本地 repo 配置,第二個是你的~/.gitconfig
,第三個是基於 git 的安裝位置。 根據哪個返回顯示憑據幫助程序,您可以嘗試使用等效的--unset
選項:
git config --local --unset credential.helper
git config --global --unset credential.helper
git config --system --unset credential.helper
如果您沒有適當的權限,最后一個可能不起作用。 因此,您可能需要在sudo
下運行最后一個才能正常工作。 FWIW,你可能已經安裝了適用於Mac OS X的預建git的圖像如果你的貓/usr/local/git/etc/gitconfig
(或/usr/local/etc/gitconfig
如果您通過自制或建築物安裝的git本地),您會看到它確實為您設置了憑證助手。 所以上面的最后一個命令將有助於解決這個問題。
其他答案非常有幫助。 credential.helper 沒有在任何列表中顯示(指定--local、--global 等),它總是顯示在“git config -l”上。 使用 --show-origin 命令顯示它來自特定於 OS X 的文件。
$ git config --show-origin --get credential.helper
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig osxkeychain
在我的情況下,運行起來更容易:
git config --get-all --show-origin credential.helper
它輸出包括配置文件路徑的完整列表:
file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig osxkeychain
file:/Users/yourname/.gitconfig !aws codecommit credential-helper $@
然后打開配置文件:
sudo vim /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig
並注釋掉credential.helper=osxkeychain
配置本身( git config --unset credential.helper
)是不夠的。
確保也git-credential-osxkeychain
任何git-credential-osxkeychain
進程(如此處所述),或者查看重新啟動后問題是否仍然存在。
另外,當使用 GitHub for Mac 時,請檢查是否有此工具內部使用的配置。
請記住,單獨的git config
將檢查系統、全局和本地配置文件。
注意:使用 git 2.9,您可以簡單地將credential.helper
設置為“空字符串”以禁用它:請參閱“如何為單個存儲庫禁用 git 的憑證助手? ”。
注意:在GitHub 中,隨着密碼被棄用而支持令牌,這個問題可能會再次出現在許多用戶身上。
就我而言( macos 11.5 BigSur ),命令行 config git config --unset credential.helper
沒有幫助,本地、全局或系統級別也沒有任何變化。 GitHub的幫助也沒有解決問題。
解決方案是:
使用git config --get-all --show-origin credential.helper
查找配置文件,如上面Kim T所述。您可能會得到並輸出如下:
file:/usr/local/git/etc/gitconfig osxkeychain
file:/Users/XYZ/.gitconfig osxkeychain
如果您和我一樣是 macos 新手,您可能需要導航到文件位置。 只需復制上面show-origin
命令的每個輸出,轉到 Finder 並在轉到菜單中選擇“轉到文件夾”,然后粘貼文件位置。
在每個配置文件中,注釋掉osxkeychain ,如下所示:
[credential]
helper = osxkeychain
應該成為#[credential]
# helper = osxkeychain
您可能需要獲得編輯文件的權限。 在命令行中編輯時使用sudo
或在 Finder 中右鍵單擊文件時轉到菜單上的“獲取信息”。
然后從回購推或拉。 系統會再次要求您輸入密碼,但現在應該提供您的個人訪問令牌。
瞧,魔術應該發生。
在 MacOS 12.1 上,沒有任何未unset
的命令可以完成這項工作。
但是,以下工作:
git config --add credential.helper ""
這允許防止 git 在鑰匙串中存儲密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.