Przejdź do głównej zawartości

SSH Keypair Setup for GitHub on Mac

Open Terminal

What is Terminal? A text-based application that allows you to run commands on your Mac using the command line.

How to open Terminal:

  1. Press Cmd + Space to open Spotlight
  2. Type "Terminal" and press Enter
  3. Alternative: Go to Applications → Utilities → Terminal

1. Generate SSH Key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

When prompted:

  • Press Enter for default location (~/.ssh/id_rsa)
  • Enter passphrase (recommended for security)

2. Add Key to SSH Agent

Start ssh-agent:

eval "$(ssh-agent -s)"

Add key to agent:

ssh-add ~/.ssh/id_rsa

3. Copy Public Key

pbcopy < ~/.ssh/id_rsa.pub

Alternative method:

cat ~/.ssh/id_rsa.pub

Then manually copy the output.

4. Add Key to GitHub

  1. Go to GitHub.comSettingsSSH and GPG keys
  2. Click New SSH key
  3. Add descriptive title (e.g., "MacBook Pro 2024")
  4. Paste key into "Key" field
  5. Click Add SSH key

Direct link: https://github.com/settings/ssh/new

5. Test Connection

ssh -T git@github.com

Expected response:

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

Configure Git (if needed)

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

Clone Repository Example

git clone git@github.com:username/repository.git

Troubleshooting

Permission denied error:

ssh -vT git@github.com

Check if key is loaded:

ssh-add -l

Re-add key if missing:

ssh-add ~/.ssh/id_rsa