【问题标题】:Github OpenSSH asking for password for an https linkGithub OpenSSH 要求输入 https 链接的密码
【发布时间】:2019-04-21 16:07:02
【问题描述】:

我正在尝试推送到远程存储库。远程来源是 https 链接。但是,当我尝试推送时,会提示输入我的用户名,然后 OpenSSH 弹出窗口会询问我的密码。输入我的密码(或个人访问令牌)后,我收到错误

remote: Password authentication is not available for Git operations.
remote: You must use a personal access token or SSH key.
remote: See https://******/settings/tokens or https://******/settings/ssh
fatal: unable to access 'https://******': The requested URL returned error: 403

git 配置文件如下。特别是所有链接看起来都是 https,而不是 ssh,所以我不知道为什么 OpenSSH 要求输入密码。上周我能够推动并且(据我所知)我没有改变任何东西。从那以后,我当然没有推过其他任何地方。

core.symlinks=false
core.autocrlf=true
core.fscache=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
push.default=simple
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=******
user.email=******
user.username=******
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://******
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

【问题讨论】:

标签: git github


【解决方案1】:

错误消息是因为您的帐户设置了双重身份验证(或可能是单点登录)。启用 2FA 后,GitHub 不再允许您使用密码进行身份验证。

您可以选择使用 SSH 密钥推送到您的帐户,也可以创建个人访问令牌,以代替 HTTPS 的密码。如果您使用的是 Windows,则可以使用内置的凭据助手将加密的令牌存储在 Windows 凭据存储中,因此您只需输入一次。

由于您使用的是 GitHub 或 GitHub 企业实例,请注意,如果您希望令牌访问私有存储库(或公共存储库为“public_repo”),令牌需要至少包含“repo”权限,如果您的组织使用单点登录系统,您必须启用single sign-on for that token。如果您选择使用 SSH,则必须在必要时为您的 SSH 密钥启用 SSO。

即使您没有使用 SSH,您也会看到 OpenSSH askpass 窗口的原因是 Git for Windows 利用该工具提示您输入密码,因此您无需输入终端。

【讨论】:

    【解决方案2】:

    首先,确保考虑所有带有git config -l 的git config。
    并且 grep 用于 InsteadOf 指令,这可能会更改您在 SSH 中的 https URL,或者相反。

    git config -l | grep -i insteadof
    

    然后,检查(针对 HTTPS URL)您的凭据缓存,其中 Git 将默认提供旧帐户/密码(已缓存)的凭据(GitHub 帐户和密码)。

    查看您是否有一个 credential helper,它会缓存您的(旧帐户)凭据(用户名/密码),用于对您进行身份验证。

    git config credential.helper 
    

    在 Mac 上,作为 commentedArpit J,只需转到/打开您的钥匙串访问权限->搜索 github.com 相关文件->并在那里编辑凭据。

    见“Updating credentials from the OSX Keychain

    例如,在 Windows 上,这将是 Windows Credential Managers
    打开 Windows Credential Store,查看第一个用户是否在那里注册:删除该条目,您将能够与第二个用户进行身份验证。

    (这里是 BitBucket 的一个例子)

    在命令行中,如seen here:

    git credential reject
    protocol=https
    host=github.com
    <empty line here>
    

    然后设置新的用户名和密码:

    git credential fill
    protocol=https
    host=github.com
    <empty line here>
    

    输入git help credential了解详细信息。

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 2016-09-20
      • 2011-05-14
      • 2013-05-23
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多