如何从 Git 中删除缓存的凭据?
How to remove cached credentials from Git?
我运行:
$ git config credential.helper store
然后:
$ git push origin master
推送后,我输入了我的凭据,它们被保存了。
我了解到它们以明文形式存储,所以现在我想删除我的凭据,使其不被默认保存和输入。
我该怎么做?
您的凭据是 stored in the file you (or the thing using git credential-store
) specified when you (or it) ran the command, as described in the documentation。默认值为 $HOME/.git-credentials
。您应该能够在编辑器中打开此文件并进行编辑,或者干脆将其完全删除。
请注意,您可能还想更改凭据助手,以免再次存储这些凭据。例如,参见 the git credential-cache
documentation。
运行 在终端中执行以下命令删除您存储在缓存中的凭据
git config --global --unset credential.helper
如果您希望守护进程提前退出,在超时前忘记所有缓存的凭据,您可以发出退出操作,运行 以下命令。
git credential-cache exit
因为他没有给出任何标志作为 global 或 local 或 system, 它默认会在本地使用,所以正确的方法是移动到相应的文件夹(存储库)并键入此命令
git config --local --unset credential.helper
或
git config --unset credential.helper
参考:https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-config
None 以上解决方案对我有用。我通过删除我在机器上生成的令牌撤销了访问权限。
我登录 GitHub 网页去了:
单击图片 > 设置 > 开发人员设置 > 个人访问令牌 > 删除该特定机器的令牌
对我来说,unset 命令不起作用,我删除了文件:
rm ~/.git-credentials
对我来说,所有选项都不起作用,我只是在我的存储库 .git/
中编辑了文件“config”。
cd .git/
nano config
搜索 [remote "origin"]
并在上方编辑:
url=YOUR REPOSITORY URL
(有或没有用户并通过username:password@gitlab.com/username/repository.git
)
保存并尝试推送您的存储库
None 以上对我有用。我正在使用 mac 我必须做的是从钥匙串应用程序
中手动删除我的凭据
步骤
- 确保 credential.helper 是 osxkeychain
$ git config --global credential.helper
osxkeychain
打开钥匙串应用程序
通过选择(所有项目)搜索凭据(例如使用用户名)
按删除键
运行 git 命令(推、拉等)。这应该会提示您输入新密码
Linux 用户:
我 运行 在尝试从密码身份验证切换到 PAT(个人访问令牌)时遇到了这个问题。
我使用 https 与 Github 一起工作。 Github 建议(在撰写此答案时)只需输入我的 PAT 而不是密码即可完成切换。但是,我遇到的问题是我的密码被缓存了,所以我 从来不需要输入它。
所以我必须查找我的 cached/stored 密码才能删除它,这样我就可以在出现提示时输入我的 PAT 而不是我的密码。
我在以下文件中找到了密码:
/home/MyUsername/.gitconfig
我删除了文件,下次直接粘贴PAT而不是我的密码。
Github 建议使用他们的 Git Credential Manager Core (GCM Core) 来存储凭据(来源:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git)。我也安装了它,PAT 凭据现在存储在不同的位置:
/home/MyUsername/.gcm
(这是一个文件夹)
我把这个答案写得更详细了,也许有点跑题了,因为从 2 天后(2021 年 8 月 13 日)开始,密码验证将不再可能,我想有些用户可能很难找到他们缓存的密码。
TL;DR 查找:
/home/MyUsername/.gitconfig
如果您在 windows 10,OS 中有一个凭据管理器。
转到“开始”菜单,键入“Credential Manager”,然后在此管理器中,select“Windows Credentials”,寻找“git:https//github.com”,展开它,然后你会在里面找到“删除”。
如果您只想删除一个缓存的凭据,那么可以在任何操作系统中通过从 Git 命令行驱动 Git 凭据助手 API 来完成:
假设 Git 存储库是 git.example.com 并且您使用 HTTPS 进行连接。在操作系统命令提示符处输入 Git 命令:
git credential reject
您现在位于凭证 API 的拒绝功能的命令行上。输入以下行:
protocol=https
host=git.example.com
在下一行,为您的操作系统按下“标准输入结束”键关闭命令。 Linux 和 MacOS 通常是 Ctrl-D,Windows.
可能是 Ctrl-Z
凭据现已从凭据存储中删除。由于我们使用 Git 的凭据 API 进行删除,因此后端使用哪个实现 API 的凭据存储并不重要。
在使用上述命令之前,请不要更改Git对user.email或credential.helper的配置。 运行 命令作为您用来连接远程 Git 存储库的用户 ID,而不是 super-user。
我运行:
$ git config credential.helper store
然后:
$ git push origin master
推送后,我输入了我的凭据,它们被保存了。
我了解到它们以明文形式存储,所以现在我想删除我的凭据,使其不被默认保存和输入。
我该怎么做?
您的凭据是 stored in the file you (or the thing using git credential-store
) specified when you (or it) ran the command, as described in the documentation。默认值为 $HOME/.git-credentials
。您应该能够在编辑器中打开此文件并进行编辑,或者干脆将其完全删除。
请注意,您可能还想更改凭据助手,以免再次存储这些凭据。例如,参见 the git credential-cache
documentation。
运行 在终端中执行以下命令删除您存储在缓存中的凭据
git config --global --unset credential.helper
如果您希望守护进程提前退出,在超时前忘记所有缓存的凭据,您可以发出退出操作,运行 以下命令。
git credential-cache exit
因为他没有给出任何标志作为 global 或 local 或 system, 它默认会在本地使用,所以正确的方法是移动到相应的文件夹(存储库)并键入此命令
git config --local --unset credential.helper
或
git config --unset credential.helper
参考:https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-config
None 以上解决方案对我有用。我通过删除我在机器上生成的令牌撤销了访问权限。
我登录 GitHub 网页去了: 单击图片 > 设置 > 开发人员设置 > 个人访问令牌 > 删除该特定机器的令牌
对我来说,unset 命令不起作用,我删除了文件:
rm ~/.git-credentials
对我来说,所有选项都不起作用,我只是在我的存储库 .git/
中编辑了文件“config”。
cd .git/
nano config
搜索 [remote "origin"]
并在上方编辑:
url=YOUR REPOSITORY URL
(有或没有用户并通过username:password@gitlab.com/username/repository.git
)
保存并尝试推送您的存储库
None 以上对我有用。我正在使用 mac 我必须做的是从钥匙串应用程序
中手动删除我的凭据步骤
- 确保 credential.helper 是 osxkeychain
$ git config --global credential.helper
osxkeychain
打开钥匙串应用程序
通过选择(所有项目)搜索凭据(例如使用用户名)
按删除键
运行 git 命令(推、拉等)。这应该会提示您输入新密码
Linux 用户:
我 运行 在尝试从密码身份验证切换到 PAT(个人访问令牌)时遇到了这个问题。
我使用 https 与 Github 一起工作。 Github 建议(在撰写此答案时)只需输入我的 PAT 而不是密码即可完成切换。但是,我遇到的问题是我的密码被缓存了,所以我 从来不需要输入它。
所以我必须查找我的 cached/stored 密码才能删除它,这样我就可以在出现提示时输入我的 PAT 而不是我的密码。
我在以下文件中找到了密码:
/home/MyUsername/.gitconfig
我删除了文件,下次直接粘贴PAT而不是我的密码。
Github 建议使用他们的 Git Credential Manager Core (GCM Core) 来存储凭据(来源:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git)。我也安装了它,PAT 凭据现在存储在不同的位置:
/home/MyUsername/.gcm
(这是一个文件夹)
我把这个答案写得更详细了,也许有点跑题了,因为从 2 天后(2021 年 8 月 13 日)开始,密码验证将不再可能,我想有些用户可能很难找到他们缓存的密码。
TL;DR 查找:
/home/MyUsername/.gitconfig
如果您在 windows 10,OS 中有一个凭据管理器。
转到“开始”菜单,键入“Credential Manager”,然后在此管理器中,select“Windows Credentials”,寻找“git:https//github.com”,展开它,然后你会在里面找到“删除”。
如果您只想删除一个缓存的凭据,那么可以在任何操作系统中通过从 Git 命令行驱动 Git 凭据助手 API 来完成:
假设 Git 存储库是 git.example.com 并且您使用 HTTPS 进行连接。在操作系统命令提示符处输入 Git 命令:
git credential reject
您现在位于凭证 API 的拒绝功能的命令行上。输入以下行:
protocol=https
host=git.example.com
在下一行,为您的操作系统按下“标准输入结束”键关闭命令。 Linux 和 MacOS 通常是 Ctrl-D,Windows.
可能是 Ctrl-Z凭据现已从凭据存储中删除。由于我们使用 Git 的凭据 API 进行删除,因此后端使用哪个实现 API 的凭据存储并不重要。
在使用上述命令之前,请不要更改Git对user.email或credential.helper的配置。 运行 命令作为您用来连接远程 Git 存储库的用户 ID,而不是 super-user。