Setting up GitHub SSH on Linux
Carl Padilla
Posted on May 20, 2024
Setting up GitHub SSH on Linux is a great way to securely manage your repositories. Here’s a step-by-step guide to help you set it up:
Step 1: Check for Existing SSH Keys
First, you need to check if you already have an SSH key:
ls -al ~/.ssh
If you see files like id_rsa
and id_rsa.pub
, you already have an SSH key.
Step 2: Generate a New SSH Key
If you don't have an SSH key, you can generate a new one:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-
-t rsa -b 4096
: Specifies the type of key and bit length. -
-C "your_email@example.com"
: Adds a comment with your email.
You'll be prompted to save the key to a specific file location. Press Enter to accept the default location (/home/your_username/.ssh/id_rsa
). Next, you'll be asked to enter a passphrase for added security (optional but recommended).
Step 3: Add SSH Key to the SSH Agent
Start the SSH agent:
eval "$(ssh-agent -s)"
Add your SSH private key to the SSH agent:
ssh-add ~/.ssh/id_rsa
Step 4: Add SSH Key to Your GitHub Account
- Copy your SSH key to the clipboard:
cat ~/.ssh/id_rsa.pub
- Log in to your GitHub account.
- Go to Settings -> SSH and GPG keys.
- Click New SSH key.
- Enter a descriptive title, and paste your SSH key into the "Key" field.
- Click Add SSH key.
Step 5: Test Your SSH Connection
To verify that your setup is working, run:
ssh -T git@github.com
You should see a message like this:
Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.
Step 6: Configure Git to Use SSH
Finally, make sure your Git configuration uses the SSH URL for GitHub. When cloning repositories, use the SSH link:
git clone git@github.com:username/repository.git
And that’s it! Your GitHub SSH setup on Linux is complete. Now you can securely manage your repositories with ease. If you have any questions or run into any issues, feel free to ask!
Posted on May 20, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.