GitHub SSH keys: from zero to a working git push
Create an SSH key, load it into the agent, register it with GitHub, and verify which identity Git uses for a repository.
Before you start
- Git is installed.
- You have access to a GitHub account and repository.
Check the repository remote
Start by confirming that the repository uses the GitHub host and the intended owner.
git remote -vAn SSH remote normally looks like git@github.com:OWNER/REPOSITORY.git.
Create a key
ssh-keygen -t ed25519 -C "your-email@example.com"Accept the default filename unless you already use that key path for another account.
Load the key
On macOS or Linux:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519On Windows PowerShell, start the OpenSSH authentication agent and add the key from your profile's .ssh directory.
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519Register the public key
Copy the contents of id_ed25519.pub, then add it to the SSH keys page of the GitHub account that should access the repository. Never upload or share the private file without the .pub suffix.
Test before pushing
ssh -T git@github.comSuccessful authentication identifies the GitHub username. It does not automatically grant write permission to every repository, so also confirm organization membership, repository access, and branch protection.
Correct the remote when necessary
git remote set-url origin git@github.com:OWNER/REPOSITORY.git
git remote -vFor multiple GitHub accounts, define SSH host aliases and assign a different identity file to each alias.
Errors this tutorial helps prevent
Frequently asked questions
Yes. Repository access is granted to the GitHub account that owns the key, not separately to the key for each repository.