Introduction

Cloning a GitHub repository over SSH takes just a few steps. Once your SSH key is set up, you can connect without entering your GitHub username and password each time.

Create an SSH key

Open a terminal and run:

ssh-keygen -t ed25519 -C "your_github_email@example.com"

Press Enter to accept the default file location (~/.ssh/id_ed25519), passphrase etc.

This creates two files: the private key (id_ed25519) and the public key (id_ed25519.pub). Keep the private key secret. Only share the public key.

Add the public key to GitHub

Print the public key in your terminal:

cat ~/.ssh/id_ed25519.pub

Copy the entire output. On GitHub, open Settings → SSH and GPG keys → New SSH key, give it a recognizable title, paste the key, and save it.

You can check the connection with this command:

ssh -T git@github.com

The first time, you may be asked to verify GitHub’s host key; check its fingerprint against GitHub’s published SSH key fingerprints before accepting it. If the connection works, GitHub will greet you by username. It may also say that shell access isn’t provided, that’s expected.

Clone a repository

On the repository page, click Code, select SSH, and copy the URL. Then run:

git clone git@github.com:OWNER/REPOSITORY.git

Replace the URL with the one you copied. That’s it, you can now work with the repository over SSH.

Conclusions

The key setup is a one-time task. After that, use the repository’s SSH URL whenever you clone a project.