DEV Community

Eddie Gulay
Eddie Gulay

Posted on

Setting up SSH for GitHub on Linux Mint

When working with GitHub, cloning repositories over SSH is faster and more secure than using HTTPS. If you’re setting it up for the first time, it can feel like a maze of commands and errors. This guide walks you through generating an SSH key, adding it to GitHub, and configuring your machine to authenticate seamlessly.


1. Check for Existing SSH Keys

First, check if you already have SSH keys on your system:

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

If you see files like id_ed25519.pub or id_rsa.pub, you already have keys. Otherwise, continue to the next step.


2. Generate a New SSH Key

Generate a new Ed25519 key pair (recommended):

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Replace your_email@example.com with the email tied to your GitHub account.
  • When prompted for a file name, press Enter to use the default (~/.ssh/id_ed25519), or specify your own (e.g., mygithubkey).

If you chose a custom name, move the files into ~/.ssh:

mv ~/path/to/mygithubkey ~/.ssh/
mv ~/path/to/mygithubkey.pub ~/.ssh/
Enter fullscreen mode Exit fullscreen mode

Set the correct permissions:

chmod 600 ~/.ssh/mygithubkey
chmod 644 ~/.ssh/mygithubkey.pub
Enter fullscreen mode Exit fullscreen mode

3. Start the SSH Agent and Add the Key

Start the SSH agent:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Add your private key:

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

Verify it was added:

ssh-add -l
Enter fullscreen mode Exit fullscreen mode

4. Add the Public Key to GitHub

Display your public key:

cat ~/.ssh/mygithubkey.pub
Enter fullscreen mode Exit fullscreen mode

It will look something like this:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAEXAMPLEKEYSTRING user@example.com
Enter fullscreen mode Exit fullscreen mode

Copy the entire line, then go to:
GitHub → Settings → SSH and GPG keys → New SSH key.

  • Give it a title (e.g., Linux Mint Laptop).
  • Paste the key.
  • Save.

5. Test the Connection

Run:

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

If everything is set up correctly, you’ll see:

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

6. Clone Repositories with SSH

Now you can clone repositories using the SSH URL:

git clone git@github.com:your-username/your-repo.git
Enter fullscreen mode Exit fullscreen mode

7. Optional: Configure SSH for Multiple Keys

If you use multiple keys, configure SSH to always use the right one for GitHub. Edit your config:

nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Add:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/mygithubkey
Enter fullscreen mode Exit fullscreen mode

Save and exit. Now GitHub will always use that key automatically.

Top comments (0)