ChatGPT解决这个技术问题 Extra ChatGPT

github: No supported authentication methods available

i use github and have successfully added and synched files on my laptop in the past.

as of recent i started getting "PuTTY Fatal Error: Disconnected: No supported authentication methods available" after running:

git pull origin master (or push)

however

ssh git@github.com returns the correct response: ERROR: Hi username! You've successfully authenticated, but GitHub does not provide shell access Connection to github.com closed.

after digging around on github i found this morcel:

No supported authentication methods available You should be aware of the environment variable GIT_SSH, which is used by git to find your ssh-speaking client, if ssh doesn’t work for you. The git install may be using plink.exe (via GIT_SSH) to perform the authentication. If so, make sure you have pageant.exe running, and the key you created for github loaded into it. This provides the key to plink.exe; without it, the above error will occur.

not sure what plink.exe or peagant.exe is.. and the fact that ssh git@github.com seems to authenticate correctly makes me wonder what the best solution here is.. i certainly don't want to overcomplicate my setup if not necessary.


R
Rex Morgan

You can create a file named ".profile" in your home directory, for me that's C:\Users\[user]

Inside that file, put the following line of code:

GIT_SSH="/usr/bin/ssh.exe"

This will set the GIT_SSH environment variable to use the ssh client included with git.

The .profile script gets executed when you start your Git Bash command line.

Edit: This is my .profile. It will ask you for your password the first time you start the git command prompt, then will remember it from then on, until you reboot your computer. Very handy so you don't have to keep entering your password each time you want to do something.

SSH_ENV="$HOME/.ssh/environment"
GIT_SSH="/usr/bin/ssh.exe"

function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cygwin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi

+1 I've had nothing but problems when using Putty/Pageant for git's ssh needs. Using the built in ssh client works wonders. This explains why ssh git@github.com returns fine if you execute it yourself, but letting git use the configured tools (Putty/Pageant) doesn't.
For me that's just GIT_SSH="/bin/ssh.exe" (on Windows). Thanks!
@Justin are you using the mingw32 prompt?
Using cygwin in Windows 7, the above answer worked but I needed to the GIT_SSH to .bash_profile and not .profile
In my case with Windows 10 using Git Bash it is GIT_SSH="D:\Program Files\Git\usr\bin\ssh.exe"
J
Joseph Dykstra

Using TortoiseGit

TortoiseGit > Settings ... Network ... SSH Client: C:\Program Files\Git\usr\bin\ssh.exe

Location my vary. On one computer it was in C:\Program Files (x86)\Git\bin\ssh.exe

https://i.stack.imgur.com/hBxoh.png


thanks. this worked. note: you might have to hunt around for exactly where 'ssh.exe' lives on a given machine. for me it was C:\Program Files\Git\usr\bin\ssh.exe (probably on an out-of-date machine)
C
Community

"... not sure what plink.exe or peagant.exe is ..."

Since you ask: plink & pageant are part of the PuTTY suite, which is an implementation of SSH that supports Linux & Windows and is completely dominant on Windows.

SSH

Secure Shell (SSH) is a cryptographic network protocol for securing data communication. It establishes a secure channel over an insecure network in a client-server architecture, connecting an SSH client application with an SSH server. Common applications include remote command-line login, remote command execution, but any network service can be secured with SSH.

if you ever used Telnet, it's like that (but more secure): it allows you to remotely access the bash shell (command line) of a Linux host.

PuTTY

PuTTY is a free and open-source terminal emulator, serial console and network file transfer application. It supports several network protocols, including SCP, SSH, Telnet, rlogin ...

On Windows it's the dominant software for remotely accessing a Linux host's command line under the SSH protocol (above). In Windows, .exe extensions are for executables. So those notes about plink.exe & pageant.exe probably don't apply if you're in Linux. PuTTY includes

Plink: a command-line interface to the PuTTY back ends Pageant: an SSH authentication agent for PuTTY, PSCP and Plink

From (http://en.wikipedia.org/wiki/Secure_Shell#Key_management)

When the public key is present on the remote end and the matching private key is present on the local end, typing in the password is no longer required ... for additional security the private key itself can be locked with a passphrase.

So github is hosted on a Linux machine and uses SSH to secure the connection. SSH either authenticates with passwords or keys, many hosts (github?) only authenticate with keys. You setup is apparently trying to authenticate with a key. Keys and hosts are not one-for-one: you can have two keys for the same host and/or two hosts for the same key, so they need to be managed. If you are in Windows, then your SSH session is probably accessed through plink and your keys are probably managed by Pageant.

Import the key you need each time you load Pageant. If you followed guides that said "import your key", and saw that it worked, but it doesn't work now, see Chapter 9: Using Pageant for authentication.

One last tip if you are on Windows: you may have multiple instances of the PuTTY suite installed by various tools. TortoiseGit, for example, installs its own.


v
vaughan

I experienced this problem because my GIT_SSH was pointing to the TortoiseSVN version of Plink.exe. I changed it to point to the TortoiseGit version, restarted cmd and it worked.

I can't remember exactly, but the TortoiseSVN version might have been 32-bit version, and the TortoiseGit version was 64-bit (located in Program Files, not Program Files (x86)).

Double-check your GIT_SSH env var.

I prefer to use git with normal cmd.exe (in Console2 of course)


You remember correctly; I had the same issue, with GIT_SSH pointing to the 32-bit TortoiseSVN version of TortoisePlink.exe. Moving it over to TortoiseGit's version worked.
J
Jon Schneider

If you're using Pageant and are getting the error described in the question after rebooting your PC (or otherwise closing and reopening Pageant):

The error can be caused by Pageant not having your GitHub SSH key actively loaded. By default, Pageant does NOT automatically load the keys from the previous session when it starts up.

To load the key:

Open Pageant. (On Windows, if Pageant is running, it'll have an icon in the system tray. Double-click that.) Click the Add Key button, and proceed to add your existing GitHub SSH key.

To avoid this problem in the future, you can configure Pageant to automatically load your key when it starts up. (Pageant will automatically prompt you for a password if your key is password-protected.)

Steps to do this (assuming you already have Pageant configured to run when Windows starts):

Find the shortcut used by Windows to run Pageant when Windows starts. (It may be in the Startup folder, which can be opened by Start > Run > shell:startup) In the shortcut's Properties dialog, append the full path and filename of the SSH key file to the "Target" field.

Reference and full details: http://blog.shvetsov.com/2010/03/making-pageant-automatically-load-keys.html


S
Simon East

For TortoiseGit Users on Windows

Originally, I used to setup most of my Github/Bitbucket repositories using the SSH repository URLs as (originally) it used to be the only convenient way to prevent TortoiseGit from prompting for your password on every single action.

But setting TortoiseGit up this way was always hair-pullingly painful. Every time it took me hours to set up correctly, as the default installation options never seemed to work (even as of 2016, sheesh!).

But TortoiseGit now has better password management for HTTPS, and Github actually recommends using HTTPS URLs wherever possible.

SSH URL: git@github.com:User/repo-name.git HTTPS URL: https://github.com/User/repo-name.git

The benefits of HTTPS are:

No managing or generating of SSH keys

No need to have pageant.exe constantly running (which requests your password on each launch)

Using TortoiseGit from Australia, I find that clones over HTTPS are 5-10x faster than SSH


+ 'git config --global http.sslVerify false'
B
BlueRaja - Danny Pflughoeft

My issue was that I was attempting to use my github username. Apparently when using Github (or is it a Git thing?), if you use key-based authentication, you need to set your username to git.

I'm not sure why you even need a username at all - perhaps someone more knowledgeable can explain that?


When cloning a private repository, it'd be a URL such as git@github.com:username/Repository.git. I'm not entirely sure on the science behind it either but it seems git is a generic username for every Github account
PLink/Pageant works fine. This is the actual issue, and using something like ssh://git@github.com/myname/repo.git will work great. Nice work. As for why, I assume it's to lock down security. The 'git' user has its login disabled, so no one can break into the system that way. They have to have a valid key to even talk to Github, and once they have a valid key, they can match it against the user to log them in.
D
Dmitriy

Worked for me on Windows 8: GIT_SSH variable was pointing to plink.exe, Changed it in the system settings to point to the ssh binary, and that has fixed the problem. To find out full path to the ssh, run:

where ssh

L
Lismore

To resolve this issue this was what I did.

I was using Git Bash on Windows 10

I started Pageant, pressed Add Key,

https://i.stack.imgur.com/5oKI0.png

navigated to C:\Users\username\.ssh folder and chose my key

https://i.stack.imgur.com/uMQ8D.png

I then attempt to do a git push and it worked this time.


Remember, you will probably have to do this each time you reboot your Windows PC - you might put Pageant into your startup folder as a shortcut with the correct command line argument to your private key file, but if you've set a password on your private key when you created it, you'll need to remember to right-click on the Pageant icon in your tool tray, select "Add key", and fill it in after each reboot.
a
atorres757

On my Windows 7 machine running Github for Windows using git version 1.8.3.msysgit.0. I found that updating my system environment variable GIT_SSH to C:\Program Files (x86)\Git\bin\ssh.exe seemed to do the trick. This also fixed my issue with contacting OpenShift's git repo.


w
wip

I had a similar issue after updating GitExtensions to version 3.3.0.7719

Somehow it reverted my authentication settings to use PuTTY instead of OpenSSH.

In that version here is the menu I used to enable OpenSSH again:

https://i.stack.imgur.com/4dMIN.png


F
Fabien Haddadi

I just solved the exact same issue by setting GIT_SSH env var to ssh. Just these 3 letters.

I strongly discourage Windows 10 users to set GIT_SSH to anything else than just ssh string (no extension), to maximise cross operability between Windows Terminal, git bash, cmd, and even PHP Storm. Obviously, your %PATH% will have to have ssh.exe in its way.

I recommend you install Git for Windows, and you add C:\Program Files\Git\usr\bin down your %PATH%

If you ever reinstall Git for Windows, be ready to set it again, and the install will ask you to specify a "plink". Little does it know that "ssh" will work to. That installer will anyway refuse anything else than an absolute path.

May I dare reminding that you obivously should restart your console or IDE after changing GIT_SSH value and/or your path.

This answer relates to solving this issue: "Cannot spawn ssh" when connecting to Github, but ssh -T git@github.com works?


C
Community

Same error, different solution noted here - Problem connecting to GitHub on Windows, even via PuTTY


C
Community

I encountered this same problem, however the GIT_SSH solution appeared to work once for me. After a computer restart I realized it was something else, as I was able to clone my private repositories with no problem using Git Bash or Command Prompt, but not in Sublime Text 3 with the SublimeGit plugin. My solution was simple and is actually what @BlueRaja - Danny Pflughoeft mentioned but I thought it could use some direction ;)

Basically you just need to edit ~/.ssh/config and ensure the username is git. You can also tell it to use a specific SSH key for Github -- My ~/.ssh/config file looks like the following:

Host gh
    Hostname github.com
    User git
    IdentityFile ~/.ssh/github_rsa.pub

I have a specific key for Github due to the number of other things I do throughout my day, but if you've only got one then it usually will be ~/.ssh/id_rsa.pub like Github explains here.

I know everyone has a different solution, but I'll leave this here for anyone who may encounter this article without a fix. Good luck!


Z
Zymotik

I got this error when using TortoiseGit to clone a repository from GitHub. Fixed by clicking "Load Putty Key" and selecting a key file (*.pkk) in the Git clone dialogue.


S
Sprachprofi

In Windows 10, if you did a typical installation including Putty, none of the above solutions worked for me, I had to go into the control panel and specifically the system variables, changing GIT_SSH to D:\Program Files\Git\usr\bin\ssh.exe there (it was linking to plink.exe and no amount of modifying .profile or whatever convinced it to change that, only editing the system variables).


This is the only one that worked for me, after painstakingly applying every other more voted solution.
e
eabrand

You can get plink & pageant from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

They are PuTTY tools.


c
cowlinator

I got this problem (direct ssh worked, but git pull failed) due to my git remote not being what I thought it was.

Yes, yes, I know it's a stupid mistake, but it happens and it's worth checking.

Use git remote -v