Fix Git errors : Permission denied , Cannot spawn , No supported authentication methods available

Recently, I came across few errors of Git and found very time consuming to fix those. Let’s discuss what are those errors and how we can fix it.

Error : Permission denied (publickey). fatal : could not read from remote repository

Git permission denied error
Git permission denied error

This error came while trying to push changes to remote repository using ssh keys. This error means we need to provide information about SSH key. it can be done by setting environment variable GIT_SSH.

There are many different types of ssh tool that are being used like ssh provided by Git or TortoisePlink.exe in my case, provided by Tortoise git.

We can use below command to set environment variable GIT_SSH

set GIT_SSH=D:\Program Files\TortoiseGit\bin\TortoisePlink.exe

However, after this when I tried to run Git push command, received new error

Git Error - Cannot Spawn
Git Error – Cannot Spawn

Error : cannot Spawn : No such file or directory

This was very tricky error to fix. However we have two solution for this error.

Solution 1:

Reason for this error was space in path for TortoisePlink.exe.

Either we can uninstall Git or TortoiseGit and then perform fresh install in folder without any space.

Or, You can copy complete bin folder in path where there is no space.

Or, we can use Symbolic link feature of Windows where virtual folder (link) can point to actual folder. We can create Symbolic link for path without any space by using below command


mklink /J newFolderName OriginalFolderName

Windows Symbolic Link creation
Windows Symbolic Link creation

As shown in above image, new symbolic folder by name “SymbolicLink_TortoiseBin” created. we can then use below command to set GIT_SSH variable


set GIT_SSH=D:\SymbolicLink_TortoiseBin\TortoisePlink.exe

As we can see in above command, we are using symbolic folder. After this we can execute Git push command without any issue.

Solution 2 – Worked for me very well

Set path of bin folder of tortoiseGit in PATH variable in Advance settings of WIndows. After setting bin folder path use below command to set GIT_SSH environment variable


set GIT_SSH=TortoisePlink

Now, windows should be able to locate “TortoisePlink.exe” because PATH environment variable already has information till bin folder and we can access any file in bin folder directly from windows command window.

I hope this blog will help you to resolve this issue.

P.S. In this blog , I have referred mostly “TortoisePlink.exe” however same solution will work for SSH.exe available by default when Git is installed.

Error : No supported authentication methods available (server sent: publickey)

If you are using some GUI to push changes then chances are very low that you will receive this error. However, if you are using command prompt, you may receive this error frequently. Reason for this error, we are using SSH protocol to connect to Git repository but SSH keys must be loaded into memory before making request so that it would be sent along with Git request. In my case, I use Pageant, its SSH authentication agent for PuTTY, PSCP, PSFTP, and Plink. Before running push command, we need to start this application and load existing keys. There are two ways to load SSH key : One way is by GUI where we can click on “Add Key” button.

Pageant Load existing SSH keys
Pageant Load existing SSH keys

Or we can add link in startup folder , to auto start this application whenever operating system boots with list of existing SSH key, using below syntax if Pageant is installed in C drive.

"C:\Program Files\PuTTY\pageant.exe" C:\key1.ppk C:\key2.ppk

If you want to create ANT task to load Pageant program with default SSH keys, then below Macro can be created and reused.

<macrodef name="LoadPageant">
		<sequential> 
                <echo message="Starting Pagent with default SSH keys" />  
		<exec executable="pageant">
	        <arg value="${pageant.key1}" /> 
                <arg value="${pageant.key2}" /> 
                <arg value="${pageant.key3}" /> 
                </exec>
		</sequential>
	</macrodef>

Posted

in

by

Tags:


Related Posts

Comments

2 responses to “Fix Git errors : Permission denied , Cannot spawn , No supported authentication methods available”

  1. ioioi Avatar

    Awesome, thanks 😉

  2. Jacques Avatar
    Jacques

    Tried and working, just wonderful. Thanks.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading