简体   繁体   English

Git 如何访问我的 GitHub 凭证?

[英]How is Git accessing my GitHub credentials?

I have attempted to remove Git's access to private GitHub repositories on GitHub.我试图删除 Git 对 GitHub 上私有 GitHub 存储库的访问权限。 No matter what I try, I cannot stop it from gaining access.无论我尝试什么,我都无法阻止它获得访问权限。 I therefore wish to know how it is authenticating, so I can remove access .因此,我想知道它是如何进行身份验证的,所以我可以删除 access

I have tried both methods here在这里尝试了这两种方法

First:第一的:

git config --global --unset user.name
git config --global --unset user.email
git config --global --unset credential.helper

and second第二个

git config --global --unset-all

And I've also deleted every github entry in Keychain Access.而且我还删除了钥匙串访问中的每个 github 条目。

When I open a new terminal window, and push to a private GitHub repository, it asks for by username and email ( not password), yet the push succeeds.当我打开一个新终端 window 并推送到私有 GitHub 存储库时,它通过用户名和 email (不是密码)询问,但推送成功。

Question问题

How can I find out how Git in terminal able to use my GitHub credentials to push a change to GitHub?如何了解终端中的 Git 如何能够使用我的 GitHub 凭证来推动对 GitHub 的更改?

Notes笔记

  • I'm connecting to GitHub via HTTPS (rather than SSH)我通过 HTTPS(而不是 SSH)连接到 GitHub

On most macOS systems, the credential.helper variable is not set in the global config, but in the system one, so you still have a credential helper enabled.在大多数 macOS 系统上, credential.helper变量未在全局配置中设置,而是在系统配置中设置,因此您仍然启用了凭据助手。 You can verify this by running git config --get credential.helper , which will probably print osxkeychain .您可以通过运行git config --get credential.helper来验证这一点,这可能会打印osxkeychain

If your goal is to remove the credentials, you can do that by following the steps outlined in the Git FAQ :如果您的目标是删除凭证,您可以按照 Git 常见问题解答中列出的步骤来完成

$ echo url=https://username@github.com | git credential reject

If you're just interested in whether the credential helper has any credentials, you can run this:如果您只是对凭证助手是否有任何凭证感兴趣,您可以运行以下命令:

$ echo url=https://username@github.com | git credential fill | less

That will print a line containing password= with the password.这将打印包含password=密码。 Note that in this case I've piped it to less to prevent it from being printed long-term on the screen.请注意,在这种情况下,我已将其设置为 less 以防止它在屏幕上长期打印。

Per the GitHub Docs , for macOS:根据GitHub 文档,对于 macOS:

Through the command line, you can use the credential helper directly to erase the keychain entry.通过命令行,您可以直接使用凭证助手擦除钥匙串条目。

$ git credential-osxkeychain erase
host=github.com
protocol=https
> [Press Return]

If it's successful, nothing will print out.如果成功,则不会打印任何内容。 To test that it works, try and clone a private repository from GitHub.要测试它是否有效,请尝试从 GitHub 克隆一个私有存储库。 If you are prompted for a password, the keychain entry was deleted.如果系统提示您输入密码,则钥匙串条目已被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM