SSH Config for GitHub
Learn how to configure SSH for GitHub access with a dedicated key. Covers Host alias, IdentityFile, and IdentitiesOnly for clean Git workflows.
Detailed Explanation
Setting Up SSH for GitHub
Configuring SSH for GitHub eliminates the need to enter credentials for every git push or git pull. By adding a dedicated Host entry in your ~/.ssh/config, you tell the SSH client exactly which key to use when connecting to GitHub.
Example Config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
AddKeysToAgent yes
Key Directives Explained
| Directive | Purpose |
|---|---|
Host github.com |
Matches connections to github.com |
User git |
GitHub always uses the git user for SSH |
IdentityFile |
Points to your GitHub-specific private key |
IdentitiesOnly yes |
Prevents SSH from trying other keys in the agent |
AddKeysToAgent yes |
Caches the key in ssh-agent after first use |
Why Use a Dedicated Key?
Using a separate SSH key for GitHub (rather than your default key) provides better security isolation. If one key is compromised, your other services remain unaffected. It also avoids confusion when you have keys for multiple services loaded in your SSH agent.
Generating the Key
If you don't already have a key, create one with:
ssh-keygen -t ed25519 -C "your-email@example.com" -f ~/.ssh/id_ed25519_github
Then add the public key (~/.ssh/id_ed25519_github.pub) to your GitHub account under Settings > SSH and GPG keys.
Use Case
Developers who use Git over SSH to push and pull from GitHub repositories, especially when managing multiple SSH keys for different services.