DEV Community

Cover image for Setting Up GitHub SSH Keys on Your Computer
Ashen Chathuranga
Ashen Chathuranga

Posted on • Edited on

Setting Up GitHub SSH Keys on Your Computer

This guide provides step-by-step instructions to set up SSH keys for secure and efficient interaction with GitHub repositories.


Prerequisites

  • Ensure Git is installed on your system. If not, download and install it from Git for Windows.
  • A GitHub account.

Steps to Set Up SSH Keys

1. Configure Git with Your User Information

Open Git-Bash and run the following commands to set your Git username and email address globally. Replace Your Name and your_email@example.com with your details.

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

2. Generate an SSH Key Pair

Open CMD and use the ssh-keygen command to generate a new SSH key pair. Replace your_email@example.com with your GitHub email address.

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • When prompted for a file location, press Enter to accept the default: /c/Users/YOU/.ssh/id_ed25519.
  • Optionally, set a passphrase for added security.

3. Start the SSH Agent

Enable and start the SSH agent to manage your SSH keys. Use the following commands in PowerShell (run as Administrator):

Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
Enter fullscreen mode Exit fullscreen mode

4. Add Your SSH Key to the Agent

Using CMD add the generated private key to the SSH agent for authentication.

ssh-add c:/Users/YOU/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

Replace YOU with your system username if necessary.


5. Copy the Public Key to Your Clipboard

Copy the contents of your public key file to your clipboard for adding it to GitHub:

clip < ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

6. Add the SSH Key to GitHub

  1. Log in to your GitHub account.
  2. Go to Settings > SSH and GPG Keys.
  3. Click New SSH Key.
  4. Provide a title (e.g., "Laptop SSH Key").
  5. Paste the public key from your clipboard into the Key field.
  6. Click Add SSH Key.

7. Verify the SSH Connection

Run the following command to confirm the connection with GitHub:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

If successful, you will see a message similar to:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Conclusion

Your SSH key is now configured for GitHub. You can securely push, pull, and manage your repositories without entering your GitHub credentials repeatedly.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs