Git Clone Using Ssh Failed in Windows Due to Permission Issue

git clone using ssh failed in Windows due to permission issue

If your public/private key doesn't have the standard name C:\Users\Toshiba\.ssh\id_rsa(.pub), but C:\Users\Toshiba\.ssh\github_rsa.pub, then you need an ssh config file

Host mysite
Hostname mysite.net
User myuser
Port 2888
IdentityFile C:\Users\Toshiba\.ssh\github_rsa.pub

That would allow you to do

git clone mysite:/home/myuser/.git/project.git

Test it first wih ssh -Tvvv mysite, and then ssh mysite ls.

Make sure the environment variable %HOME% is defined to C:\Users\Toshiba

You have another example in "SSH error on push to an existing project Permission denied (publickey)"

git clone ssh permission denied

git clone ssh://github.com/username/repository.git is wrong. You should be doing:

git clone ssh://git@github.com/username/repository.git

or better yet:

git clone git@github.com:username/repository.git

Git: How to solve Permission denied (publickey) error when using Git?

If the user has not generated a ssh public/private key pair set before

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)

First start by setting up your own public/private key pair set. This
can use either DSA or RSA, so basically any key you setup will work.
On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
  • On OS X run: cat id_rsa.pub | pbcopy
  • On Linux run: cat id_rsa.pub | xclip
  • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil)
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
  • git config --global user.name "bob"
  • git config --global user.email bob@...
    (don't forget to restart your command line to make sure the config is reloaded)

That's it you should be good to clone and checkout.

Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney)
[1]: https://github.com/sitaramc/gitolite

-

If the user has generated a ssh public/private key pair set before

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

Permission failure cloning in Git in Windows

In your Powershell session, try:

$env:GIT_SSH_COMMAND='ssh -Tv'; git clone git@gitlab.com:myuser/myrepo.git

And see where SSH is looking for your default id_rsa/id_rsa.pub key pair.

Make sure, if the private key is passphrase-protected, to launch ssh-agent first.

The OP mentions:

Apparently, Git doesn't use native OpenSSH.

That is false. Maybe GitHub Desktop does not use OpenSSH, as seen in desktop/desktop issue 5641: "Desktop does not use OpenSSH on Windows if running, favours embedded SSH"

Hence the workaround:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

But Git itself does:

D:\prgs\gits\current\bin>where ssh
D:\prgs\gits\current\usr\bin\ssh.exe

D:\prgs\gits\current\bin>ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020

This is more recent than the Windows one:

C:\WINDOWS\System32\OpenSSH\ssh.exe -V
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

(Winver: 1909, build 18363.836=

That is why I always launch tools with my own PATH

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

That way, I am sure I will use Git tools first (incuding an OpenSSH one) before anything else.

Can't clone, can SSH. Permission denied (publickey).

The git credential manager is only involved for caching credentials (username/password) for HTTPS URL, not SSH.

Only the ssh-agent could be involved, for caching a possible passphrase, if the private key was defined with it.

I would try first using the full path, since ~ might not be interpreted by the remote shell, but the local (which has a different path for ~):

git clone ssh://user@host/home/user/test.git
# or
git clone user@host:/home/user/test.git

If not, in a git bash session, type:

export GIT_SSH_COMMAND='ssh -v'
git clone ...

The OP confirms in the discussion it works in a bash session:

In git bash, I started the ssh-agent,

added the key there, then it worked.

Git: Permission denied (publickey) fatal - Could not read from remote repository. while cloning Git repository

It looks like a permissions issue - not a Windows 7 issue.

Your ssh key is not authorised - Permission denied (publickey).

You need to create a public ssh key and ask the administrator of the Git repository to add the ssh public key

Information on how to do this: Saving ssh key fails

GitHub Error Message - Permission denied (publickey)

GitHub isn't able to authenticate you. So, either you aren't setup with an SSH key, because you haven't set one up on your machine, or your key isn't associated with your GitHub account.

You can also use the HTTPS URL instead of the SSH/git URL to avoid having to deal with SSH keys. This is GitHub's recommended method.

Further, GitHub has a help page specifically for that error message, and explains in more detail everything you could check.



Related Topics



Leave a reply



Submit