如何重置“git credential-osxkeychain”中存储的凭据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11067818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:56:31  来源:igfitidea点击:

How do you reset the stored credentials in 'git credential-osxkeychain'?

macosgitgithub

提问by nirvana

I've followed the GitHub instructions for setting up my account, and I'm able to clone, but I'm unable to push remotely.

我已按照 GitHub 说明设置我的帐户,并且我能够克隆,但我无法远程推送。

When I do a "git push" I get the 403 error. It has the correct URL. I tried a "git credential-osxkeychain get" to see what it was giving, and this prints out the wrong credentials.

当我执行“git push”时,我收到 403 错误。它具有正确的 URL。我尝试了“git credential-osxkeychain get”来查看它提供了什么,这会打印出错误的凭据。

I believe what happened is the first time it asked for the credentials, I thought it was another application asking, and it put the wrong ones in.

我相信发生的事情是它第一次要求提供凭据,我以为是另一个应用程序在询问,并且输入了错误的凭据。

I just need to reset it so that it uses the correct keychain item for my GitHub account.

我只需要重置它,以便它为我的 GitHub 帐户使用正确的钥匙串项目。

I've tried:

我试过了:

git credential-osxkeychain erase
git credential-osxkeychain set

The program never gives any prompts. Set will say "bad input" if I don't do the right thing. I tried putting in "password=password", etc., but then when I do a "get" I still get the old ones.

该程序从不给出任何提示。如果我没有做正确的事情,Set 会说“输入错误”。我尝试放入“ password=password”等,但是当我执行“获取”时,我仍然得到旧的。

I can't figure out where these are being stored, as they are not in .gitconfigure. Further there are no recent keychain items that could be it. (I have several GitHub accounts in my keychain and it is not using any of them.)

我无法弄清楚这些存储在哪里,因为它们不在 .gitconfigure 中。此外,没有最近的钥匙串项目可能是它。(我的钥匙串中有几个 GitHub 帐户,但它没有使用任何一个。)

采纳答案by nirvana

The solution turned out to be this:

解决方案原来是这样的:

The command git credential-osxkeychainwas using the firstGitHub account entry in my keychain. This one was not the one that had access to the projects in question.

该命令git credential-osxkeychain使用了我钥匙串中的第一个GitHub 帐户条目。这个人不是有权访问相关项目的人。

I resolved the problem by touching the account in Keychain Access so that its date changed (I think I just changed the comment) and now that it became the most recent GitHub account it became the first one returned to credential-osxkeychain, and thus everything worked.

我通过触摸 Keychain Access 中的帐户解决了这个问题,以便它的日期发生变化(我想我只是更改了评论),现在它成为最新的 GitHub 帐户,它成为第一个返回到 credential-osxkeychain 的帐户,因此一切正常.

A better form of support for multiple GitHub accounts would be nice, but it is likely that most people only have one primary account and don't run into this problem.

为多个 GitHub 帐户提供更好的支持形式会很好,但很可能大多数人只有一个主帐户并且不会遇到这个问题。

回答by maz

From Terminal:

从终端:

 $ git credential-osxkeychain erase
 host=github.com
 protocol=https
 <press return>

NOTE: after you enter “protocol=https” above you need to press ~~RETURN~~ TWICE

注意:在上面输入“protocol=https”后,需要按~~RETURN~~TWICE

回答by benzado

I'm not sure how to erase through the command line, but it's fairly easily to do it through the Keychain Access app. Just go to Applications -> Utilties -> Keychain Access, then enter "github.com". You can either delete the invalid item or update the password from with the app.

我不确定如何通过命令行擦除,但通过 Keychain Access 应用程序很容易完成。只需转到应用程序 -> 实用程序 -> 钥匙串访问,然后输入“github.com”。您可以删除无效项目或使用应用程序更新密码。

回答by MacFreek

git-credential-osxkeychain stores passwords in the Apple Keychain, as noted above.

git-credential-osxkeychain 将密码存储在 Apple Keychain 中,如上所述。

By default, gitcredentials only considers the domain name. If you want Git to consider the full path (e.g. if you have multiple GitHub accounts), set the useHttpPathvariable to true, as described at http://git-scm.com/docs/gitcredentials.html. Note that changing this setting will ask your credentials again for each URL.

默认情况下,gitcredentials 只考虑域名。如果您希望 Git 考虑完整路径(例如,如果您有多个 GitHub 帐户),请将useHttpPath变量设置为true,如http://git-scm.com/docs/gitcredentials.html 中所述。请注意,更改此设置将针对每个 URL 再次询问您的凭据。

回答by echristopherson

Try running /Applications/Utilities/Keychain Access.

尝试运行/Applications/Utilities/Keychain Access

回答by Amit kumar

On Mac, use the command git credential-osxkeychain erase.

在 Mac 上,使用命令git credential-osxkeychain erase.

OR remove manually from keychain from ApplicationsUtilitiesKeychain Access. Then remove the github.com keychain. Then use push; it will ask for the keychain access; then deny.

或者从ApplicationsUtilitiesKeychain Access手动从钥匙串中删除。然后删除 github.com 钥匙串。然后使用push;它将要求钥匙串访问;然后否认。

It will ask for the new username and password, add it then pushes a file for that.

它会询问新的用户名和密码,添加它然后推送一个文件。

After git pushI found this error. Then I use the upper case- issue:

git push我发现这个错误之后。然后我使用大写 - 问题:

remote: Permission to user1/file.git denied to user2(previously exist user ). fatal: unable to access 'https://github.com/xxxxxxxxxxxx/': The requested URL returned error: 403

远程:对 user1/file.git 的权限被拒绝给 user2(以前存在 user )。致命:无法访问“ https://github.com/xxxxxxxxxxxx/”:请求的 URL 返回错误:403