Github OpenSSH asking for password for an https link

那年仲夏 提交于 2021-02-19 05:59:45

问题


I'm attempting to push to a remote repository. The remote origin is an https link. However when I attempt to push I get a prompt for my username, and then an OpenSSH popup window asks for my password. After entering my password (or a personal access token) I get the error

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

The git config file is below. In particular all the links look to be https, and not ssh, so I don't know why OpenSSH is asking for a password. I was able to push last week and (as far as I know) I haven't changed anything. I certainly haven't pushed anywhere else since then.

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

回答1:


The error message is because your account has two-factor authentication (or possibly single sign-on) set up. When you have 2FA enabled, GitHub no longer lets you use your password to authenticate.

You can either choose to use an SSH key to push to your account, or you can create a personal access token, which can be used in place of a password for HTTPS. If you're on Windows, you can use the built-in credential helper to store that token encrypted in the Windows Credential Store so you only need to enter it once.

Since it looks like you're using GitHub or a GitHub enterprise instance, note that the token needs to contain at least the "repo" permission if you want it to access private repositories (or "public_repo" for public ones), and if your organization uses a single sign-on system, you must enable single sign-on for that token. If you choose to use SSH, you must similarly enable SSO for your SSH key if necessary.

The reason you're seeing the OpenSSH askpass window even though you're not using SSH is because Git for Windows leverages that tool to prompt you for your password so you don't need to enter a terminal.




回答2:


First, make sure to consider all git config with git config -l.
And grep for InsteadOf directive, that could change your https URL in SSH, or the opposite.

git config -l | grep -i insteadof

Then, check (for an HTTPS URL) your credential caching, where Git will be default provide the credentials (GitHub account and password) of an old account/password (cached).

See if you have a credential helper that would have cached your (old account) credentials (username/password) used to authentication you.

git config credential.helper 

On Mac, as commented by Arpit J, just goto/open your keychain access->search for github.com related file->and edit credentials there.

See "Updating credentials from the OSX Keychain"

On Windows for example, that would be the Windows Credential Managers.
Open the Windows Credential Store, and see if the first user is registered there: delete that entry, and you will be able to authenticate with the second user.

(Here is an example for BitBucket)

In command-line, as seen here:

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

and then to set the new username & password:

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

Type git help credential for detailed info.



来源:https://stackoverflow.com/questions/53372238/github-openssh-asking-for-password-for-an-https-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!