# Adding a New SSH Key for a New GitHub Account

> Guide for managing multiple SSH keys on macOS when you already have existing keys.

* * *

## Current SSH Keys

| Key | Purpose |
| --- | --- |
| `id_ed25519` | Personal key |

* * *

## Step 1: List Existing SSH Keys

```bash
ls -la ~/.ssh/
```

Check what keys already exist so you can pick a unique name for the new one.

* * *

## Step 2: Generate a New SSH Key

```bash
ssh-keygen -t ed25519 -C "your-work-email@company.com" -f ~/.ssh/id_ed25519_work
```

*   Replace `your-work-email@company.com` with your actual work email.
    
*   When prompted for a passphrase, enter one (recommended) or press Enter to skip.
    
*   This creates two files:
    
    *   `~/.ssh/id_ed25519_work` (private key — never share this)
        
    *   `~/.ssh/id_ed25519_work.pub` (public key — this goes to GitHub)
        

* * *

## Step 3: Add the Key to Your SSH Agent

```bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_work
```

To make this persist across reboots, you can also add `AddKeysToAgent yes` in your SSH config (see Step 4).

* * *

## Step 4: Update SSH Config (~/.ssh/config)

Edit the file:

```bash
nano ~/.ssh/config
```

Add a new host entry for your work GitHub account:

```plaintext
# Primary Github (existing)
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  AddKeysToAgent yes

# Work Github (new)
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  AddKeysToAgent yes
```

### How This Works

*   `github.com` uses your primary key (existing behavior, unchanged).
    
*   `-github-work` is an alias that routes to github.com but uses your work key.
    

* * *

## Step 5: Copy the Public Key to Clipboard

```bash
pbcopy < ~/.ssh/id_ed25519_work.pub
```

* * *

## Step 6: Add the Key to GitHub

1.  Log into your **work GitHub account** at https://github.com
    
2.  Go to **Settings** > **SSH and GPG keys**
    
3.  Click **New SSH key**
    
4.  Title: something descriptive (e.g., "MacBook Pro - Work")
    
5.  Key type: **Authentication Key**
    
6.  Paste the key from your clipboard
    
7.  Click **Add SSH key**
    

* * *

## Step 7: Test the Connection

```bash
ssh -T git@github-work
```

Expected output:

```plaintext
Hi <work-username>! You've successfully authenticated, but GitHub does not provide shell access.
```

* * *

## Step 8: Using the Work Key for Repos

### Cloning a new repo:

```bash
git clone git@github-work:org-name/repo-name.git
```

### Updating an existing repo's remote:

```bash
git remote set-url origin git@github-work:org-name/repo-name.git
```

### Check which remote a repo uses:

```bash
git remote -v
```

* * *

## Quick Reference

| Task | Command |
| --- | --- |
| List all SSH keys | `ls -la ~/.ssh/` |
| Start SSH agent | `eval "$(ssh-agent -s)"` |
| Add key to agent | `ssh-add ~/.ssh/id_ed25519_work` |
| List keys in agent | `ssh-add -l` |
| Copy public key | `pbcopy < ~/.ssh/id_ed25519_work.pub` |
| Test connection | `ssh -T git@github-work` |
| View SSH config | `cat ~/.ssh/config` |
| Remove key from agent | `ssh-add -d ~/.ssh/id_ed25519_work` |

* * *

## Troubleshooting

### "Permission denied (publickey)"

*   Verify the key is added to the agent: `ssh-add -l`
    
*   Verify the public key is added to the correct GitHub account
    
*   Verify `~/.ssh/config` has the correct `IdentityFile` path
    

### Wrong GitHub account used

*   Check which host alias you're using in the remote URL
    
*   Run `ssh -T git@github-work` to confirm which account the alias resolves to
    

### SSH agent not running after reboot

*   Re-run: `eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519_work`
    
*   Or add it to your `~/.zshrc` to auto-start
    

* * *

*Created: 2026-04-08*
