Setting up SSH keys for GitHub allows you to securely authenticate without needing to enter your username and password every time. Here’s a step-by-step guide documentation and video:
Step 1: Check for existing SSH keys
Before generating a new key, check if you already have one:
bashCopy codels -al ~/.ssh
If you see files like id_rsa.pub
or id_ed25519.pub
, you already have a key.
Step 2: Generate a new SSH key
If you don’t have a key or want to create a new one, run the following command (replace your_email@example.com
with your GitHub email):
bashCopy codessh-keygen -t ed25519 -C "your_email@example.com"
If your system doesn’t support ed25519
, you can use RSA instead:
bashCopy codessh-keygen -t rsa -b 4096 -C "your_email@example.com"
- When prompted, choose a file to save the key (
/home/you/.ssh/id_ed25519
or the default). - Enter a passphrase (optional but recommended).
Step 3: Add your SSH key to the ssh-agent
To ensure the SSH key is used, add it to the ssh-agent
:
- Start the
ssh-agent
in the background:
bashCopy codeeval "$(ssh-agent -s)"
- Add your SSH key to the agent:
bashCopy codessh-add ~/.ssh/id_ed25519
(Or ~/.ssh/id_rsa
if using RSA.)
Step 4: Add the SSH key to your GitHub account
Now, you need to add the SSH public key to GitHub:
- Copy the SSH public key to your clipboard:
bashCopy codecat ~/.ssh/id_ed25519.pub
(Or ~/.ssh/id_rsa.pub
.)
- Log into GitHub, go to Settings > SSH and GPG keys > New SSH key.
- Paste your key and save.
Step 5: Test the SSH connection
To confirm that everything is set up properly, run:
bashCopy codessh -T git@github.com
You should see a message like this:
bashCopy codeHi your_username! You've successfully authenticated, but GitHub does not provide shell access.
This confirms that SSH is set up correctly for GitHub.
Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.