如何强制 git 提示输入凭据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18947897/
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-19 09:05:50  来源:igfitidea点击:

How do I force git to prompt for credentials?

macosgitauthenticationgithub

提问by jhfrontz

Weeks ago (and in a fog), I needed to make some changes to something hosted at github. I was directed by someone-who-knows-more-than-me (SWKMTM) via phone on exactly what to type in order to configure, pull down, modify, push back and then activate things. Part of this involved issuing instructions to gitthat said I as SWKMTM.

几周前(在迷雾中),我需要对 github 上托管的内容进行一些更改。我被一个比我更了解的人 (SWKMTM) 通过电话指导我确切地输入什么,以便配置、下拉、修改、推回然后激活事物。其中一部分涉及向git说我作为 SWKMTM 的人发出指令。

Now that I've had time to learn a bit about git/github (as well as to recall my github login information), I've gone back and tried to substitute my identity for SWKMTM on my client machine (a la git config --global user.nameand git config --global user.email). After doing this, I can perform the same update activities as before. However, I have yet to be prompted to enter my github password (i.e., there is NO request to enter my github password). I'm assuming that something has been cached identifying me as SWKMTM (and that I must've done something in the earlier fog that involved entering SWKMTM's github password) -- either locally or by implicitly sending my SSH public key.

既然我已经有时间学习一些关于 git/github 的知识(以及回忆我的 github 登录信息),我又回去尝试在我的客户端机器上用我的身份替换 SWKMTM(a lagit config --global user.namegit config --global user.email)。执行此操作后,我可以执行与以前相同的更新活动。但是,我还没有被提示输入我的 github 密码(即没有要求输入我的 github 密码)。我假设已经缓存了一些东西,将我标识为 SWKMTM(并且我必须在早期的迷雾中做了一些涉及输入 SWKMTM 的 github 密码的事情)——无论是在本地还是通过隐式发送我的 SSH 公钥。

I've searched around in vain for .*rc files and configuration directories for anything that resembles credentials that might be associated with SWKMTM (in hopes of dispatching said credentials and forcing git to prompt for new ones). I've similarly failed to find anything at github that might tell if there is some sort of aliasing for public keys (and how it might be purged).

我已经在 .*rc 文件和配置目录中搜索了任何类似于可能与 SWKMTM 相关联的凭据的内容,但徒劳无功(希望分发所述凭据并强制 git 提示输入新凭据)。我同样未能在 github 上找到任何可以说明公钥是否存在某种别名的信息(以及如何清除它)。

I've also tried the advised "git config -l"for any credential helper and have found none.

我还为任何凭证助手尝试了建议的“git config -l”,但没有找到。

How can I force github to forget that I've been masquerading as SWKMTM?

我怎样才能强迫 github 忘记我一直在伪装成 SWKMTM?

[sidenote: this is on MacOS with no indication in config files that credential-osxkeychain is used. Only after using GIT_TRACE=1on a push was it obvious where the credentialing was stored.]

[旁注:这是在 MacOS 上,在配置文件中没有说明使用了 credential-osxkeychain。只有在使用GIT_TRACE=1推送后,凭证的存储位置才很明显。]

采纳答案by knittl

user.nameand user.emailhave nothing to do with credentials, they are just strings that are put into each commit you make to store your authorship information.

user.name并且user.email与凭据无关,它们只是放入您为存储作者信息所做的每次提交中的字符串。

Git normally authenticates you via SSH, so you have to either copy your SSH private key from the other machine to your new client, or create a new key pair and add the public part to your github profile.

Git 通常通过 SSH 对您进行身份验证,因此您必须将您的 SSH 私钥从另一台机器复制到您的新客户端,或者创建一个新的密钥对并将公共部分添加到您的 github 配置文件中。



OK, after extensive discussion in the chat it turns out that Git was using the osxkeychain credential helper which provided previously stored credentials.

好的,经过在聊天中的广泛讨论,事实证明 Git 正在使用 osxkeychain 凭证助手,它提供了先前存储的凭证。

Remove your stored credentials from your OSX keychain or disable the crendential helper (credential.helperconfig option) in Git to be prompted for authentication again.

从 OSX 钥匙串中删除存储的凭据或禁用credential.helperGit 中的凭据助手(配置选项)以再次提示进行身份验证。