【问题标题】:Force git to always ask for a password强制 git 始终要求输入密码
【发布时间】:2018-02-16 11:36:24
【问题描述】:

我在多台计算机上工作,我会确保 git 在我推送时不会存储我的密码。所以简而言之,我希望 git 总是询问我的 github 密码。

这可能吗?

我比在 Mac 上感到沮丧,由于某种原因,它总是将我的密码存储在钥匙串中,我每次都必须手动删除它。

我正在使用命令行。

编辑:

这个答案给了我解决问题的线索:

How do I disable git's credential helper for a single repository?

在终端运行这个:

git config --local credential.helper ''

或者,您可以编辑 .git/config 文件并拥有以下内容:

[credential] helper = ''

我没有 root 密码(出于某种原因,管理员密码不是有效的 root 密码,请看一下)。

【问题讨论】:

标签: git macos passwords


【解决方案1】:
git config --global --unset credential.helper
git config --system --unset credential.helper

在 Windows 中: 通过单击开始按钮 打开用户帐户 开始按钮的图片、单击控制面板、单击用户帐户和家庭安全(或单击用户帐户,如果您连接到网络域),然后单击用户帐户。在左窗格中,单击管理您的凭据。 Windows 7:控制面板\用户帐户\凭据管理器

技巧:https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage 您可以将记住权限超时更改为 0(零)。

ma​​cOS

尝试运行 /Applications/Utilities/Keychain Access

右键,选择Delete

如果您想从 macOS 终端使用命令行,请键入

git credential-osxkeychain erase
host=github.com
protocol=https

【讨论】:

    【解决方案2】:

    据我了解,这将是一个 SSH 问题。您不想为某个主机(即 GitHub)使用 MacOS 密钥链。

    这是我实现这一目标的方法

    SSH 的默认配置是从~/.ssh/config 加载的(~ 是你的主目录)。

    在您最喜欢的编辑器中打开该文件,并添加您的 GitHub 主机,并将其配置为不将您的密钥存储在密钥链/代理中。

    例如

    Host <short name for your host, perhaps my-github or github.com>
      Hostname github.com
      UseKeychain no
      AddKeysToAgent no
    

    注意:如果您希望规则适用于您可以使用的所有主机

    Host *
    

    如果您的简称不是 github.com,请说 super-server-github 编辑您的 &lt;path-to-repo&gt;/.git/config 以将其反映为

    [remote "origin"]
            url = git@super-server-github:activehacker/gfs.git
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-26
      • 2014-12-18
      • 2014-07-30
      • 1970-01-01
      • 2021-03-29
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多