Github: 不支持可用的身份验证方法

我使用 github,并成功地添加和同步文件在我的笔记本电脑在过去。

从最近开始,我开始得到“ PuTTY 致命错误: 断开连接: 不支持可用的身份验证方法”后,运行:

Git 拉动原点控制器(或推动)

然而

Ssh git@github.com 返回正确的响应: 错误: 您好,用户名! 您已经成功地进行了身份验证,但是 GitHub 不提供 shell 访问 与 github.com 的连接关闭。

在 Github 上查了一下,我发现了这个 Morcel:

不支持可用的身份验证方法 如果 ssh 不能为您工作,那么您应该知道环境变量 gIT _ SSH,GIT 使用它来查找使用 ssh 的客户端。GIT 安装可能使用 plink.exe (通过 GIT _ SSH)来执行身份验证。如果是这样,请确保运行了 pageant.exe,并将为 github 创建的密钥加载到其中。这提供了 plink.exe 的密钥; 如果没有它,就会发生上面的错误。

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.

116363 次浏览

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

They are PuTTY tools.

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

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

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)

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.

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?

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!

"... 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.

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.

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

tortoisegit

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:

  1. Open Pageant. (On Windows, if Pageant is running, it'll have an icon in the system tray. Double-click that.)
  2. 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):

  1. 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)
  2. 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

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

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

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

To resolve this issue this was what I did.

I was using Git Bash on Windows 10

I started Pageant, pressed Add Key,

enter image description here

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

enter image description here

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

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:

enter image description here

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).

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?