Setting Up SSH Authentication with GitHub for Secure Access with 2FA GitHub Accounts
Type this in to create GitHub Keys for your computer
ssh-keygen -t rsa -b 4096 -C "email@example.com"
Type the following on the local machine to add your key to the agent.
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.
Type the following to verify you have completed the setup properly
ssh -T firstname.lastname@example.org
Here is how to clone new repositories instead of using https://
git clone email@example.com:USERNAME/Repo.git
Update existing repositories to use SSH instead of https
git remote set-url origin firstname.lastname@example.org:USERNAME/Repo.git
This is the best way to clone and push updates to repositories if you have 2-Factor enabled on your GitHub account.