Search code examples
gitgithubpermission-deniedgit-clone

Can't clone an existing repository with ssh, and ssh config seems fine


Here's my situation: I have two private repositories.

Currently i added a remote just for one of them by cloning it.

$ git remote -v
origin  [email protected]:syra37fGIT/temp.git (fetch)
origin  [email protected]:syra37fGIT/temp.git (push)

ssh is configured correctly i think, since:

i generated both private (id_rsa) and public (id_rsa.pub) keys

$ ls -al ~/.ssh
total 28
drwxr-xr-x 1 Pietro 197121    0 Mar  5 00:18 ./
drwxr-xr-x 1 Pietro 197121    0 Mar 17 09:19 ../
-rw-r--r-- 1 Pietro 197121 3389 Mar  5 00:18 id_rsa
-rw-r--r-- 1 Pietro 197121  747 Mar  5 00:18 id_rsa.pub
-rw-r--r-- 1 Pietro 197121 2790 Mar  5 00:29 known_hosts

the public key is correctly setted into my github account Personal settings/SSH and GPG keys

public key setted on account

the private key also seems correctly registered

$ eval `ssh-agent -s`
Agent pid 7696

$ ssh-add
Identity added: /c/Users/Pietro/.ssh/id_rsa ([email protected])

as proof, i can actually push commits into the added repository whithout problems (no password required since ssh is active)

(master)$ echo -e "\ndamn u damn" > README.txt
(master)$ git add .
(master)$ $ git commit -m "damn u commit"
          [master dae7dfd] damn u commit
            1 file changed, 2 insertions(+), 4 deletions(-)
(master)$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 263 bytes | 263.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:syra37fGIT/temp.git 
  54bc492..dae7dfd  master -> master

and also the authentication test works

$ ssh -T [email protected]
Hi syra37fGIT! You've successfully authenticated, but GitHub does not provide shell access.

Given this, when i try to clone the other repository, the error message below appears...

$ git clone [email protected]:syra37fGIT/Angular.git
Cloning into 'Angular'...
\302\[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Every tips suggested in https://help.github.com/en/articles/error-permission-denied-publickey is satisfied (i'm on windows machine). Where i'm doing wrong?

Just a tip: there's a chance that one of there two repositories was first cloned with https and then transformed into ssh (FROM HTTPS TO SSH)... I can't tell if this can be a clue or not to the problem.

UPDATE: as the comment below suggests, the problem was that while visually the repo string was correct, the actual one sent was wrong. The issue is solved.


Solution

  • As seen here, if the command is the result of a copy-paste, it can embark invisible special characters which will make the command fails.

    A basic double-check to do in this instance is to type again the command manually, and see if the issue persists.

    As commented here, '\302\226' is 0xC2 0x96 aka U+0096 in UTF-8 encoding.
    See more here:

    The original source for this was likely a byte 0x96 in some single-byte 8-bit encoding that has been transcoded incorrectly somewhere along the way. Probably this was originally a Windows CP1252 en dash "", which has byte value 96 in that encoding, which has been translated to UTF-8 as though it was latin-1 (ISO/IEC 8859-1), which is not uncommon.