I have gone through many other posts about the above error, but they all seem to be for a different OS, or for some different reason.

I am running Windows 8.1. I have git installed (I am very new to git), and have signed up to gitlab, create a project there, created and added the key (as per instructions), however when I try and do a push, I get the

Pushing to [email protected]:myusername/Test1.git
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Now when I created my ssh key using

ssh-keygen -t rsa -C "[email protected]

it did create the files in the local project folder, and not under C:\Users\Peter (my home folder)

So, copied the single file (known_hosts) I deleted the existing .ssh folder, and created using bash, and then copied in the above together with the created id_rsa.pub and idrsa.key files.

From Git Gui, if I go to Help | Show SSH Key is reports "Found a public key in ~/.ssh/id_ras.pub

From bash, my permissions on the folder are.

drwxr-xr-x    1 Peter    Administ        0 Jun 14 09:35 .ssh

and the permissions on the files within are..

$ ls .ssh  -l
total 2
-rw-r--r--    1 Peter    Administ      403 Jun 13 18:26 id_rsa.pub
-rw-r--r--    1 Peter    Administ     1766 Jun 13 18:26 idrsa.key
-rw-r--r--    1 Peter    Administ      184 Jun 13 18:11 known_hosts

I am assuming I need to fix the permissions here?

So I go into the .ssh folder and try a chmod 777 *

But then when I use ls -l to see the permissions they have not changed

Likewise when I try that on the actual directory .ssh, permissions stay as they are

So, the questions are

  1. Am I on the right track here, is it the permissions of the folder/files that are the problem
  2. If so, how can I fix this (on Windows 8.1)

I am at a complete loss of what to try next

Thanks in advance for any help!

1

There are 1 answers

3
VonC On BEST ANSWER

Am I on the right track here, is it the permissions of the folder/files that are the problem

Not really: "permission denied" is sent back by the GitLab server, as it doesn't recognize your ssh public key.

Firstly, as mentioned in GitLab ssh keys doc page:

Copy-paste the key (id_rsa.pub content) to the 'My SSH Keys' section under the 'SSH' tab in your user profile. Please copy the complete key starting with ssh- and ending with your username and host.

Secondly, ssh will locally look for the private and public keys in %HOME%.
And %HOME% isn't defined by default in Git, unless you launch git-cmd.exe or git-bash.exe packaged with the latest Git for Windows 2.4.x+.

So:

  • make sure to grep PortableGit-2.4.3.1-2nd-release-candidate-64-bit.7z.exe, and unzip it anywhere you want (for example in: c:\prgs\git\PortableGit-2.4.3.1-2nd-release-candidate-64-bit)
    Don't intall the old obsolete msysgit 1.9.5 from git-scm.com. As I explained, it will soon be phased out.
  • add c:\prgs\git\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin to your %PATH% (it includes ssh.exe)
  • launch c:\prgs\git\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\git-cmd.exe, and see that %HOME% is define (set HOME).
    It should be defined to your %USERPROFILE% by default (c:\Users\<yourLogin>)
  • generate your ssh keys (or copy your existing one in %HOME%\.ssh). Don't worry about chmod or rights.
  • make sure your ssh public key is copied in your GitLab ssh key page.

Then, test if ssh works:

ssh -Tv [email protected]

Now you can start pushing.