DEV Community

Carl Padilla
Carl Padilla

Posted on

Setting up GitHub SSH on Linux

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode
  • -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)"
Enter fullscreen mode Exit fullscreen mode

Add your SSH private key to the SSH agent:

ssh-add ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Step 4: Add SSH Key to Your GitHub Account

  1. Copy your SSH key to the clipboard:
   cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode
  1. Log in to your GitHub account.
  2. Go to Settings -> SSH and GPG keys.
  3. Click New SSH key.
  4. Enter a descriptive title, and paste your SSH key into the "Key" field.
  5. Click Add SSH key.

Step 5: Test Your SSH Connection

To verify that your setup is working, run:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

You should see a message like this:

Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (1)

Collapse
 
warwait profile image
Parker Waiters

Setting up GitHub SSH on Linux sounds straightforward with your guide! Could you perhaps write a similar post for setting up SSH on a macOS system? Thanks!