Cannot clone repos with git@github.com at the beginning?

Viewed 20

Everything works fine when repo starts with https://*** But when I'm trying to clone this repo git clone git@github.com:crate-ci/committed.git it shows the following error:

git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

I assume it requires SSH key but why? I thought SSH key is required only for your private repos. This repo is public isn't it?

1 Answers

GitHub requires that you have a valid SSH key in order to access repositories over SSH. Anonymous access is only accessible over HTTPS.

The reason is the the way the two protocols do authentication. HTTPS authenticates every request independently, in this case, using a token. If no authentication is provided, then the request is anonymous.

However, SSH authenticates the connection up front, and can then run multiple commands using that same connection. The repositories you want to access are part of the command and aren't known until authentication has already happened. If GitHub didn't require that you be authenticated, then your SSH client would simply not authenticate at all, and then you wouldn't be able to access any private repositories. Consequently, the only way to make sure that you can access all repositories is to force authentication on every connection.

Related