This page looks best with JavaScript enabled

How to Use SSH with Github

 ·  ☕ 2 min read

Setting Up SSH Authentication with GitHub for Secure Access with 2FA GitHub Accounts

ssh

Creating SSH Keys

Type this in to create GitHub Keys for your computer

1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Notes:

  • I typically save this in ~/.ssh/github
  • You don’t have to put a password if you aren’t worried about security

Adding the New Key to GitHub and Local SSH-Agent

Type the following on the local machine to add your key to the agent.

1
2
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github

Copy the contents of ~/.ssh/github.pub to the new key field in GitHub. If you have xclip installed type this cat ~/.ssh/github.pub | xclip -sel clip to copy the contents.

github-pub

Test GitHub SSH Access

Type the following to verify you have completed the setup properly

1
ssh -T git@github.com

SSH GitHub Clone Syntax and Updating Repositories

Here is how to clone new repositories instead of using https://

1
git clone git@github.com:USERNAME/Repo.git

Update existing repositories to use SSH instead of https

1
git remote set-url origin git@github.com:USERNAME/Repo.git

Conclusion

This is the best way to clone and push updates to repositories if you have 2-Factor enabled on your GitHub account.

Contact Me

I live stream on Chris Titus Tech YouTube Channel every Friday at 10 AM CST and archive clips to Titus Tech Talk. I also regularly publish to christitus.com, but if you’d like to contact me directly or want to contribute to help keep these articles and videos being made consider joining the CTT members.

Two Memberships exist:

  • ChrisTitus.com Members Section (CC Only)
    • Full Archive of All Unlisted Live Streams
    • Direct Members Only Email
    • Monthly Members Only Video
    • Starting at $2 Per Month (100% of Proceeds goes to Chris Titus Tech)
  • YouTube Chris Titus Tech Membership (All Payments Accepted)
    • YouTube Emojis for Comments and Live Chat
    • YouTube Badges that changes based on membership time for comments and chat.
    • All YouTube comments are highlighted when I review comments daily.
    • Immediate Access to Full Live Streams
    • $4.99 Per Month (70% of the Proceeds goes to Chris Titus Tech)
Share on

Chris Titus
WRITTEN BY
Chris Titus
Tech Content Creator