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\github_rsa.pub, then you need an ssh config file
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
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://email@example.com/username/repository.git
or better yet:
git clone firstname.lastname@example.org: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], 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)
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
Permission failure cloning in Git in Windows
In your Powershell session, try:
$env:GIT_SSH_COMMAND='ssh -Tv'; git clone email@example.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:
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020
This is more recent than the Windows one:
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
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
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
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.