gitgithubversion-control

Cloning a git repo and its throwing an error


I tried cloning a repo like this in my VS Code Terminal, in the folder I am trying to clone the repo into. I am on Windows.

git clone git@github.com:username/shopping-list.git .
Cloning into '.'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

and I have already verified my ssh connection

ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

what should i do?

Update: i fixed the issue by adding the ssh keys to the ssh agent by

eval 'ssh-agent -s'
ssh-add ~/.ssh/github_ssh_name

through git bash on the folder where the cloned repo is supposed to go. but i need to keep adding them before every clone. any way to fix this issue.

Update 2: issue fixed, i deleted and generated new pair of keys, it was probably because i tried to change the default name of my ssh keys.


Solution

  • You don't necessarily need to use an SSH agent; just configure ssh to use the correct key when connecting to GitHub. Add something like the following to your .ssh/config file (creating the file if necessary):

    Host github
    Hostname github.com
    User git
    IdentityFile ~/.ssh/github_ssh_name
    

    This will let you clone with

    git clone github:username/shopping-list.git .
    

    as connections to the alias "github" will pull the necessary information from your SSH configuration.