Setup SSH Keys for GitHub access, Authorize SSO, use with IDE

Background

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.

Where

I have tried these steps on the Git Bash terminal on windows as well as terminal on Mac.

How

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

Authorize SSO

  • If Single Sign On is enabled, clicked on the "Configure SSO button" and selected "Authorize"

Test

  • Added SSH key to ssh-agent and executed the following steps:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
    ssh -T git@github.com
    

[Optional] Using ssh keys with IDE (VSCode)

  • Started VS Code IDE from the Git Bash prompt where ssh-add is done in previous step
    code .
    

[Optional] Switch remote URLs from HTTPS to SSH

  • Updated existing remote's URL to use SSH
    git remote set-url origin git@github.com:"your-organization/your-repo.git"
    

Next

  • Would probably write about using multiple Git accounts from a single laptop - Personal Github, AWS Code Commit

Disclaimer

  • 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.

References