# 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

- Logged in to [Github](https://github.com) and navigated to [Settings --> SSH and GPG Keys](https://github.com/settings/keys)
- Clicked on "New SSH key" and pasted the public key copied in previous step

### 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
- [Connecting to GitHub with SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh)
- [Authentication](https://docs.github.com/en/authentication)
- [Authorizing an SSH key for use with SAML single sign-on](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-an-ssh-key-for-use-with-saml-single-sign-on)
- [Ed25519: high-speed high-security signatures](https://ed25519.cr.yp.to/)
