Create SSH Key
This guide will help you generate a SSH key pair and use it with your GitHub account.
Step 1: Creating the SSH Key
-
Open your terminal (Windows: Git Bash, macOS/Linux: Terminal).
-
Run the following command to generate a new SSH key pair:
ssh-keygen -t ed25519 -
When prompted for a file to save the key, press
Enterto accept the default location (~/.ssh/id_ed25519). -
Press
Entertwice to leave the passphrase empty. -
Your SSH key pair will be created, and placed in the
~/.sshdirectory. The public key ends with.pub.
Step 2: Add the SSH Key to your GitHub Account
-
Copy the contets of your public key to the clipboard:
cat ~/.ssh/id_ed25519.pub | pbcopy # macOScat ~/.ssh/id_ed25519.pub | clip # Windows (Git Bash) -
Navigate to this link GitHub settings.
-
Click on New SSH key.
-
Paste your public key into the "Key" field.
-
You can skip the "Title" field or give it a descriptive name.
-
Click Add SSH key to save it.
Step 3: Test the SSH Connection
-
In your terminal, run the following command to test the connection:
ssh -T git@github.com -
If everything is set up correctly, you should see a message like:
Hi username! You've successfully authenticated, but GitHub does not provide shell access. -
If you see a warning about the authenticity of the host, type
yesto continue.
Step 4: Cloning a Repository using SSH
Now that you have your SSH key set up, you can clone repositories using SSH:
git clone git@github.com:username/repo.git
- replace the
usernamewith your GitHub username andrepo.gitwith the repository you want to clone.