如何禁用 osxkeychain 作为 git 配置中的凭据助手?

我需要禁用 OS X: git credential-osxkeychain的凭据助手

它在全局配置文件和本地配置文件中都被禁用,实际上它启用了 永远不会ben。尽管如此,它还是记住了我的 github 登录信息。
我用的是笔记本电脑,所以我不希望自动无密码访问我的回购协议。
威尔使用 ssh 键。这是一台新计算机,整个系统的设置仍在进行中。
目前,我使用的是 https回购参考文献,而凭证助手一直在发挥作用。

这些是我的配置文件:


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 fetch) ,密钥链中的条目就会被恢复。

75847 次浏览

The config itself (git config --unset credential.helper) isn't enough.
Make sure to kill any git-credential-osxkeychain process (as described here) as well, or see if the issue persists after a reboot.

Also, when using GitHub for Mac, check if there is a config used internally by this tool.
Remember that git config alone will check for system, global and local config file.

Note: with git 2.9, you can simply set the credential.helper to "empty string" in order to disable it: see "How do I disable git's credential helper for a single repository?".

To help track down the setting, I'd try to use:

git config --local credential.helper
git config --global credential.helper
git config --system credential.helper

The first one checks the local repo config, the second is your ~/.gitconfig, and the third is based on where git is installed. Depending on which one comes back showing the credential helper, you can try using the equivalent --unset option:

git config --local --unset credential.helper
git config --global --unset credential.helper
git config --system --unset credential.helper

The last one may not work if you don't have proper permissions. So you may need to run the last one under sudo for it to work correctly. FWIW, you may have installed for the pre-built git images for Mac OS X. If you cat /usr/local/git/etc/gitconfig (or /usr/local/etc/gitconfig if you installed git via Homebrew or a building locally), you'll see that it does set up the credential helper for you. So the last command above would help fix that problem.

The other answers were very helpful. The credential.helper didn't show for me in any of the listings (specifying --local, --global, etc) and it always showed on a 'git config -l'. Using the --show-origin command showed that it was coming from an OS X-specific file.

$ git config --show-origin --get credential.helper
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig    osxkeychain

It my case it was easier to run:

git config --get-all --show-origin credential.helper

Which outputs the full list including config file paths:

file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig   osxkeychain
file:/Users/yourname/.gitconfig !aws codecommit credential-helper $@

Then open the config file:

sudo vim /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig

And comment out the line credential.helper=osxkeychain

Note: in GitHub, with passwords being deprecated in favour of tokens, this problem may come up again for many users.
In my case (macos 11.5 BigSur) the command line config git config --unset credential.helper did not help, nor did any variations on the local, global or system levels. The help from GitHub did not solve the issue either.

The solution was:

  1. look for the config files using git config --get-all --show-origin credential.helper, as mentioned by Kim T above.You'll probably get and output like:
    file:/usr/local/git/etc/gitconfig osxkeychain
    file:/Users/XYZ/.gitconfig osxkeychain

  2. If you're a macos newbie as I am, you might need to navigate to the file location. Just copy each output from the show-origincommand above, go to Finder and in the Go menu select 'Go to Folder', then paste the file location.

  3. in each of the config files, comment out osxkeychain, as featured below:
    [credential]
    helper = osxkeychain
    should become
    #[credential]
    # helper = osxkeychain
    You might need to acquire permissions to edit the files. Either use sudo when editing in the command line or go to "Get Info" on the menu when right-clicking the file in Finder.

  4. Then push or pull from the repo. You'll be asked for your password again, but should now provide your personal access token instead.

And voilà, magic should happen.

On MacOS 12.1 none of unset commands did the job.

However, the following worked:

git config --add credential.helper ""

Which allowed to prevent git to store password in the keychain.