Search code examples
linuxgitgithubsshclone

Git clone using ssh does not work with message "git@github.com: No such file or directory"


I'm trying to clone a private Github repo from my linux Mint computer using ssh. I have created a private/public key pair and registered it with Github (different than the default id_rsa). When I try ssh -vT git@github.com , I have successful authentication.

But when I make a git clone using the URL given by GitHub, I get the following error :

git clone git@github.com:benblan/{private_repo}.git
Cloning into '{private_repo}'...
git@github.com: No such file or directory
fatal: Could not read from remote repository.

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

The ssh-agent is running.

ps -eaf | grep ssh
benblan      1525    1455  0 09:58 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/im-launch cinnamon-session-cinnamon
benblan      2109    1452  0 09:59 ?        00:00:00 /usr/bin/ssh-agent -D -a /run/user/1000/keyring/.ssh

The only thing I see is that when I echo the variable SSH_AUTH_SOCK, I have a different path : /run/user/1000/keyring/ssh (no dot in front of ssh).

I could use HTTPS with Personal Access Token, but I wanted to make the ssh connection work.

Any idea?


Solution

  • Double-check your ssh client is fully installed/up-to-date:

    sudo apt update
    sudo apt install openssh-client
    

    And specify the full path for ssh and your key:

    export GIT_SSH_COMMAND="/usr/bin/ssh -i ~/.ssh/id_rsa"
    

    Then try again.


    The alternative would be to reference the same private key by a ~/.ssh/config file:

    Host gh
      Hostname github.com
      User git
      IdentityFile ~/path/to/private_key
    

    And

    git clone gh:benblan/{private_repo}.git