SSH keys are used to access and write data into your GitHub repository. Whenever you connect via SSH, you authenticate using the private key file on your local machine.
Before creating a new key, check if you already have one:
# on linux
ls ~/.ssh
# on Windows
ls c:/Users/<your name>/.ssh
Look for files like:
id_rsa id_rsa.pub or id_ed25519 id_ed25519.pub
1. Create your SSH key
You can generate your SSH key pair using ssh-keygen
. Many algorithms generate an SSH key pair. Here, we specify the Ed25519 algorithm using the -t
flag. The -C
flag allows us to add a comment to identify the key and is optional.
ssh-keygen -t ed25519 -C "[email protected]"
This generates an SSH key pair (public and private keys) in the c:/Users/<yourName>/.ssh
folder on Windows.
Your key pair is saved as:
c:/Users/<yourName>/.ssh/id_ed25519
(private)
c:/Users/<yourName>/.ssh/id_ed25519.pub
(public)
On Linux, this is usually: ~/.ssh/
. Listing the files in the folder shows two files.
ls
id_ed25519 id_ed25519.pub
2. Add the SSH Key to the SSH Agent
eval $(ssh-agent -s)
# on Linux
ssh-add ~/.ssh/id_ed25519
# on Windows
ssh-add /c/Users/<yourName>/.ssh/id_ed25519
3. Copy the public key
cat
shows the file's content. The pipe (|
) operator feeds this content as input to the clip
command. This copies the file content to your clipboard.
cat ~/.ssh/id_ed25519.pub | clip
4. Add the public key to your GitHub account
Go to GitHub → Profile Icon → Settings.
Navigate to SSH and GPG keys
Click New SSH key
Give it a title (e.g., “Laptop - June 2025”) and paste the key
Since we are using this key to sign our commits, make sure you change the "Key type" to Signing key.
5. Testing your SSH connection
ssh -T [email protected]
You should see something like this after you enter your passphrase (if you configured it while generating the SSH key pair).
If you also want to authenticate repositories with this SSH key, add the same public key again as an Authentication key under SSH and GPG keys → New SSH Key → Change "Key Type" to Authentication key.
6. Use SSH for Your Repo Remote (optional)
If your repo was cloned using HTTPS, you'll need to switch to SSH to use this key to push changes.
git remote set-url origin [email protected]:yourusername/yourrepo.git
7. Signing commits
Enable commit signing and specify SSH key format
git config commit.gpgsign true
# or enable it globally
git config --global commit.gpgsign true
Configure Git to use SSH to sign commits and tags:
git config --global gpg.format ssh
To set your SSH signing key in Git, paste the text below, substituting /PATH/TO/.SSH/KEY.PUB
with the path to the public key you'd like to use.
git config --global user.signingkey /PATH/TO/.SSH/KEY.PUB
8. Check for verification on your new commit
When committing changes in your local branch, add the -S
flag to the git commit command.
git commit -S -m "YOUR_COMMIT_MESSAGE"
# Creates a signed commit
If you configured a passphrase while setting up the SSH key, provide it. Otherwise, leave it blank.
Now, visit the commits in your repository to check the verified status.
Resources:
Top comments (2)
Thank you for this great article I see where I made a mistake and now know how to fix it
Thanks!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.