DEV Community

Kb Bohara
Kb Bohara

Posted on

SSH for GitHub Baby

Check for Existing SSH Keys

ls -al ~/.ssh
Enter fullscreen mode Exit fullscreen mode

Generate a New SSH Key

If no keys are found, generate one:

ssh-keygen -t rsa -b 4096 -C "[email protected]"
Enter fullscreen mode Exit fullscreen mode

Start the SSH Agent (optional)

Why?: The agent manages your keys and prevents you from entering your passphrase every time.

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Add SSH Key to Agent

ssh-add ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Copy the SSH Public Key

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Add the Key to GitHub

  • Go to GitHub > Settings > SSH and GPG keys > New SSH key.
  • Paste the copied key.

Test SSH Connection

ssh -T [email protected]
Enter fullscreen mode Exit fullscreen mode

Update Git Remote URL

git remote set-url origin [email protected]:uname/repo.git
Enter fullscreen mode Exit fullscreen mode

Done! You're all set to use SSH with GitHub!

Top comments (0)