Again, I needed to set up ssh keys to access Github. So, thought of capturing the steps I followed; and I signed up for 2Articles1week challenge.
What and Why
This time, I needed to access GitHub for an organization, configured for SSO (single sign-on) with 2FA (2 Factor Authentication) enabled.
I have tried these steps on the Git Bash terminal on windows as well as terminal on Mac.
Generate new SSH key and copy to clipboard
Generated a new SSH key as I am working on new laptop and do not have access to previous key pair.
ssh-keygen -t ed25519 -C <your e-mail address>
Note: By default, private and public key would be stored at ~/.ssh
Copied to clipboard:
clip < ~/.ssh/id_ed25519.pub
Copy to Git Hub account
- Logged in to Github and navigated to Settings --> SSH and GPG Keys
- Clicked on "New SSH key" and pasted the public key copied in previous step
- If Single Sign On is enabled, clicked on the "Configure SSO button" and selected "Authorize"
- Added SSH key to ssh-agent and executed the following steps:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 ssh -T firstname.lastname@example.org
[Optional] Using ssh keys with IDE (VSCode)
- Started VS Code IDE from the Git Bash prompt where ssh-add is done in previous step
[Optional] Switch remote URLs from HTTPS to SSH
- Updated existing remote's URL to use SSH
git remote set-url origin email@example.com:"your-organization/your-repo.git"
- Would probably write about using multiple Git accounts from a single laptop - Personal Github, AWS Code Commit
- If you want something quick that worked for another person, please feel free to use the steps in this article
- Please refer to the official documentation for comprehensive and latest steps.