0% found this document useful (0 votes)
25 views3 pages

SSH Cheat Sheet For GitHub

This document is a cheat sheet for managing SSH keys with GitHub, detailing steps to generate a new SSH key, add it to the SSH agent, and link it to a GitHub account. It includes instructions for testing the SSH connection, using SSH with Git, managing multiple GitHub accounts, troubleshooting common issues, and updating compromised keys. The guide emphasizes security best practices and provides command-line examples for each step.

Uploaded by

Minerva May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

SSH Cheat Sheet For GitHub

This document is a cheat sheet for managing SSH keys with GitHub, detailing steps to generate a new SSH key, add it to the SSH agent, and link it to a GitHub account. It includes instructions for testing the SSH connection, using SSH with Git, managing multiple GitHub accounts, troubleshooting common issues, and updating compromised keys. The guide emphasizes security best practices and provides command-line examples for each step.

Uploaded by

Minerva May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SSH Cheat Sheet for GitHub

1. Generate a New SSH Key

ssh-keygen -t ed25519 -C "[email protected]"

- -t ed25519: Specifies the key type.


- -C: Adds a comment (usually your email).

For older systems that don’t support ed25519, use:


ssh-keygen -t rsa -b 4096 -C "[email protected]"

Follow the prompts to:


- Choose a file location (default: ~/.ssh/id_ed25519).
- Set a passphrase (recommended for security).

2. Add Your SSH Key to the SSH Agent

eval "$(ssh-agent -s)" # Start the SSH agent


ssh-add ~/.ssh/id_ed25519 # Add your private key

3. Add the SSH Key to Your GitHub Account

1. Copy your public key:


cat ~/.ssh/id_ed25519.pub
2. Log in to your GitHub account.
3. Go to Settings > SSH and GPG keys > New SSH key.
4. Paste the copied key into the Key field and add a title.

4. Test SSH Connection

ssh -T [email protected]
You should see a message like:
Hi <username>! You've successfully authenticated, but GitHub does not provide shell
access.

5. Use SSH with Git

To clone a repository using SSH:


git clone [email protected]:<username>/<repository>.git

6. Manage Multiple GitHub Accounts

1. Edit your SSH config file:


nano ~/.ssh/config
2. Add the following configuration:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519

Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work

3. Clone repositories using the appropriate host:


- Personal: [email protected]:<username>/<repository>.git
- Work: git@github-work:<username>/<repository>.git

7. Troubleshooting

- Verify SSH Key:


ssh-add -l
- Check SSH Connection:
ssh -vT [email protected]
- Permission Issues:
Ensure correct permissions for ~/.ssh directory and files:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub

8. Update Your SSH Key

If your SSH key is compromised or expired:


1. Remove the old key from GitHub (Settings > SSH and GPG keys).
2. Generate a new key using the steps above.
3. Update your local system and GitHub account.

You might also like