GitHub SSH Key Management
Generate an SSH Key for GitHub
-Cis a comment (any label, not functionally required)-fspecifies the filename to save the key- Press Enter twice to skip setting a passphrase (or set one for security)
Add the Public Key to GitHub
- Copy the output
- Go to GitHub → Settings → SSH and GPG keys
- Click "New SSH key", give it a name, and paste the public key
Configure SSH to Use the Right Key
Edit (or create) the ~/.ssh/config file:
IdentitiesOnly yes tells SSH to use only this key instead of offering every key in your agent.
without it, it will try:
- Keys from ssh-agent
- Default files in ~/.ssh/
- ~/.ssh/id_rsa
- ~/.ssh/id_ecdsa
- ~/.ssh/id_ed25519
- ~/.ssh/id_dsa
- Any others added in recent OpenSSH versions
- Keys listed in your ~/.ssh/config for the current Host (
Host github.com)
with it, SSH uses only the key you specified — no default keys, no ssh-agent keys, no surprises.
Test SSH Connection to GitHub
this is assume I configed the ssh key correctly (using ssh-add(ssh-agent) or editing ~/.ssh/config)
Expected result:
Use case:
- You're testing if a specific key works
- You haven’t set up a config file or SSH agent
- You want a one-off manual override
Expected result:
Use SSH with Git
Use default commit message template (specific repository)
Notes
- GitHub uses
git@github.comfor all SSH connections. - SSH authentication is done via public key fingerprint, not username.
- GitHub matches the SSH key to your account during the handshake.
- You can manage multiple SSH keys by configuring
~/.ssh/configfor each host.