DEV Community

Jordan Tauscher
Jordan Tauscher

Posted on

How to Set Up SSH for GitHub on Linux: A Step-by-Step Guide

How to Set Up SSH for GitHub on Linux: A Step-by-Step Guide

If you're using GitHub on Linux and want to push or pull code in the most ergonomic way, SSH is how it's done. Since GitHub deprecated password authentication, SSH is now the standard for secure, passwordless Git operations.

In this post, I'll walk you through setting up SSH for GitHub on Linux, so you can push and pull code seamlessly.


Why Use SSH?

  • No passwords: No need to enter your credentials every time.
  • More secure: SSH keys are encrypted and harder to crack than passwords.
  • Easier workflow: Just git push and git pull without authentication prompts.

Step 1: Check for Existing SSH Keys

First, check if you already have an SSH key:

ls -al ~/.ssh
Enter fullscreen mode Exit fullscreen mode

If you see files like id_ed25519 and id_ed25519.pub (or id_rsa and id_rsa.pub), you already have a key pair. If not, proceed to generate a new one.


Step 2: Generate a New SSH Key

Run the following command, replacing the email with your GitHub email:

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Press Enter to accept the default file location.
  • Optionally, set a passphrase for extra security.

Step 3: Add Your SSH Key to the SSH Agent

Start the SSH agent and add your key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

Step 4: Add Your SSH Key to GitHub

  1. Copy your public key:
   cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode
  1. Go to GitHub → Settings → SSH and GPG keys
  2. Click New SSH key, paste your key, and save.

Step 5: Change Your Remote URL to SSH

In your repo directory, run:

git remote set-url origin git@github.com:<your-username>/<your-repo>.git
Enter fullscreen mode Exit fullscreen mode

Replace <your-username> and <your-repo> with your actual GitHub username and repository name.


Step 6: Test Your SSH Connection

Run:

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

You should see:

Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Step 7: Push Your Changes

Now you can push your changes without a password:

git push origin <your-branch-name>
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

  • Permission denied (publickey): Make sure your SSH key is added to the agent and to GitHub.
  • Could not open a connection to your authentication agent: Run eval "$(ssh-agent -s)" and try again.

Conclusion

Setting up SSH for GitHub on Linux is a one-time process that makes your Git workflow much smoother and more secure. No more password prompts, just seamless Git operations!


Have you set up SSH for GitHub? Let me know in the comments if you found this guide helpful!

Top comments (0)