Skip to content

🔑 Setting up an SSH key for GitHub

This guide explains two ways to set up an SSH key for GitHub on Linux/macOS:

  • 📘 Option 1: Manual setup
  • 🤖 Option 2: Using the provided automation script

📘 Option 1: Manual setup

1️⃣ Generate a new SSH key

Run the following command and replace <your-email@example.com> with your GitHub email:

ssh-keygen -t ed25519 -C "<your-email@example.com>" -f ~/.ssh/id_ed25519_github
````

* It will create two files:

  * `~/.ssh/id_ed25519_github` (private key)
  * `~/.ssh/id_ed25519_github.pub` (public key)
* Leave the passphrase blank (optional).

---

### 2️⃣ Start the SSH agent

```bash
eval "$(ssh-agent -s)"

3️⃣ Add your key to the agent

ssh-add ~/.ssh/id_ed25519_github

4️⃣ Configure SSH to use this key only for GitHub

Edit or create ~/.ssh/config and add:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_github

5️⃣ Add the public key to your GitHub account

Copy the public key:

cat ~/.ssh/id_ed25519_github.pub

Go to GitHub > Settings > SSH and GPG keys > New SSH key, paste it, and save.


6️⃣ Test your connection

ssh -T git@github.com

You should see a success message.


🤖 Option 2: Automated script

We provide a script that automates all the steps above.

📄 Give execution permissions to the script

chmod +x create_github_ssh_key.sh

You can find the script contents in the scripts folder: 👉 create_github_ssh_key.sh


🚀 Run the script

bash ./scripts/create_github_ssh_key.sh

The script will:

  1. ✅ Ask for your GitHub email
  2. ✅ Generate the SSH key
  3. ✅ Start ssh-agent and add the key
  4. ✅ Configure SSH to use this key only for github.com
  5. ✅ Print the public key for you to copy to GitHub

🔷 After running the script

Copy the printed public key into GitHub > Settings > SSH and GPG keys > New SSH key, then test:

ssh -T git@github.com

Notes

  • Do not share your private key (~/.ssh/id_ed25519_github) with anyone.
  • You can have multiple SSH keys for different services; just specify them in ~/.ssh/config.