How to Add SSH Key to GitHub

Summarize this article with:
Typing your password every time you push code gets old fast. Learning how to add SSH key to GitHub eliminates that friction permanently.
SSH keys use public key cryptography to authenticate your machine with GitHub’s servers. One setup, zero password prompts.
This guide walks you through the complete process: checking for existing keys, generating a new SSH key pair, configuring the ssh-agent, and registering your public key with GitHub.
Works on macOS, Windows, and Linux. Takes about 5-10 minutes.
By the end, you will clone repositories, push commits, and pull changes through a secure shell connection without touching your credentials again.
How to Add SSH Key to GitHub
Adding an SSH key to GitHub is the process of registering your public key with your GitHub account to enable secure, passwordless authentication for Git operations.
You need this when cloning private repositories, pushing code to remote branches, or setting up automated deployments.
This guide covers 6 steps requiring 5-10 minutes and no prior experience with version control security.
The whole thing works through public key cryptography. Your machine holds the private key. GitHub holds the public key. They shake hands every time you connect.
Once configured, you can clone a GitHub repository, push to GitHub, and pull from GitHub without typing credentials.
Prerequisites
Before generating your SSH key pair, confirm you have these ready:
- Operating system: Windows 10/11, macOS Monterey or later, Ubuntu 20.04+
- Terminal access: Terminal app (macOS), Git Bash (Windows), or any Linux shell
- GitHub account: Free tier works fine
- Git installed: Version 2.34.0 or higher (how to install Git if needed)
- Time needed: 5-10 minutes
No prior SSH experience required. If you understand what Git is and what GitHub is, you are set.
Step One: How Do You Check for Existing SSH Keys?
Open your terminal and run ls -la ~/.ssh to list any existing key files in your SSH directory. Look for files named ided25519, idrsa, or similar. If keys exist, you can skip generation and jump to adding them to the ssh-agent.
Action
- Open terminal: Launch Terminal (macOS/Linux) or Git Bash (Windows)
- Run command:
ls -la ~/.ssh - Check output: Look for
ided25519,ided25519.pub,idrsa, oridrsa.pub
Expected Results
If you see key files, you already have an SSH key pair.
If you get “No such file or directory,” your .ssh folder does not exist yet. No problem. The next step creates everything.
Purpose
Checking first prevents creating duplicate keys. Multiple keys work, but they add complexity to your source control management setup.
Step Two: How Do You Generate a New SSH Key?

Run the ssh-keygen command with the Ed25519 algorithm in your terminal, enter your GitHub email as the label, accept the default file location, and optionally set a passphrase. The command creates both private and public key files in your .ssh directory.
Action
- Generate key:
ssh-keygen -t ed25519 -C "youremail@example.com" - File location prompt: Press Enter to accept default
~/.ssh/ided25519 - Passphrase prompt: Enter a passphrase or press Enter for none
- Confirm passphrase: Re-enter or press Enter again
Expected Results
You will see your key fingerprint and a randomart image. Two files now exist: ided25519 (private) and ided25519.pub (public).
Why Ed25519?
GitHub recommends Ed25519 over RSA. Smaller keys, faster authentication, stronger encryption.
RSA still works if your system is older. Use ssh-keygen -t rsa -b 4096 -C "youremail@example.com" instead.
Step Three: How Do You Add the SSH Key to the SSH Agent?
Start the ssh-agent in the background, then add your private key using ssh-add. The agent manages your keys during the session and remembers your passphrase so you do not have to type it repeatedly.
Action for macOS
- Start agent:
eval "$(ssh-agent -s)" - Configure SSH: Add to
~/.ssh/config:
“ Host github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/ided25519 `
- Add key: ssh-add –apple-use-keychain ~/.ssh/ided25519
Action for Windows (Git Bash)
- Start agent: eval “$(ssh-agent -s)”
- Add key: ssh-add ~/.ssh/ided25519
Action for Linux
- Start agent: eval “$(ssh-agent -s)”
- Add key: ssh-add ~/.ssh/ided25519
Expected Results
Agent responds with a process ID like Agent pid 59566.
After ssh-add, you see “Identity added” confirmation.
Purpose
The ssh-agent handles token-based authentication behind the scenes. Without it, you would enter your passphrase for every single Git operation. Gets old fast.
Step Four: How Do You Copy the Public SSH Key?
Copy the contents of your public key file to your clipboard using platform-specific commands. Never copy the private key. Only the .pub file goes to GitHub.
Action for macOS
pbcopy < ~/.ssh/ided25519.pub
Copies directly to clipboard. No output means it worked.
Action for Windows
clip < ~/.ssh/ided25519.pub
If using PowerShell and you get a ParseError, run Get-Content ~/.ssh/ided25519.pub | Set-Clipboard instead.
Action for Linux
cat ~/.ssh/ided25519.pub
Displays the key. Select and copy manually with Ctrl+Shift+C.
Expected Results
Your clipboard contains text starting with ssh-ed25519 and ending with your email.
Purpose
The public key is your identity file that GitHub uses to verify your encrypted connection. Share it freely. The private key stays on your machine, always.
Step Five: Where Do You Add the SSH Key in GitHub?
Navigate to your GitHub account settings, access the SSH and GPG keys section, create a new SSH key entry, paste your public key, and save. The key registers immediately for remote repository authentication.
Action
- Navigate: Profile picture > Settings > SSH and GPG keys
- Click: New SSH key button
- Title field: Enter descriptive name (e.g., “MacBook Pro Work” or “Desktop Ubuntu”)
- Key type: Select “Authentication Key”
- Key field: Paste your copied public key
- Save: Click Add SSH key
Authentication vs Signing Keys
Authentication keys verify your identity for Git operations like clone, push, pull.
Signing keys verify commit authorship. Different purpose. You can add the same key as both types if needed for committing to GitHub with verified signatures.
Expected Results
GitHub may prompt for your password or two-factor code. After confirmation, the key appears in your SSH keys list with a fingerprint preview.
Step Six: How Do You Test the SSH Connection?
Run the SSH test command to verify GitHub recognizes your key, accept the host fingerprint on first connection, and confirm the authentication success message. This validates your entire setup before using it for actual git clone operations.
Action
- Run test: ssh -T git@github.com
- First-time prompt: Type yes
to add GitHub to known hosts
- Enter passphrase: If you set one during key generation
Expected Results
Success message: Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.
That warning about shell access is normal. GitHub does not allow terminal sessions. Your SSH key works for Git operations only.
What Failure Looks Like
Permission denied (publickey) means GitHub cannot find a valid key. Check that you added the correct public key and that your ssh-agent is running.
Verification
Test your setup with real Git repository operations.
Clone a Private Repository
Copy the SSH URL from any repository you have access to. Format: git@github.com:username/repo-name.git
Run git clone git@github.com:username/repo-name.git
No password prompt should appear.
Push a Test Commit
Make a small change, stage it with git add, commit, and push.
If the push completes without credential prompts, your SSH authentication works.
Confirm Remote URL
Run git remote -v in an existing repository.
SSH URLs start with git@github.com: while HTTPS URLs start with https://github.com/
Switch from HTTPS to SSH with git remote set-url origin git@github.com:username/repo.git
Troubleshooting
Permission Denied (publickey)
Issue: GitHub rejects your connection with “Permission denied (publickey)” error.
Solutions:
- Verify ssh-agent is running: eval “$(ssh-agent -s)”
- Check key is loaded: ssh-add -l
should list your key
- Confirm correct email: cat ~/.ssh/ided25519.pub
shows the label
- Re-add key to agent: ssh-add ~/.ssh/ided25519
- Verify key exists in GitHub settings
Could Not Open Connection to Authentication Agent
Issue: The ssh-add command fails because no agent is running.
Solutions:
- macOS/Linux: eval “$(ssh-agent -s)”
- Windows PowerShell (Admin): Start-Service ssh-agent
- Windows: Set ssh-agent service to automatic startup
Key Not in Standard Location
Issue: SSH cannot find your key because it uses a custom filename or path.
Solution: Create or edit ~/.ssh/config:
` Host github.com HostName github.com User git IdentityFile ~/.ssh/yourcustomkeyname `
Bad Configuration Option: UseKeychain
Issue: macOS error when using UseKeychain in config file.
Solution: Add IgnoreUnknown UseKeychain before the UseKeychain line in your SSH config. Older OpenSSH versions do not recognize this option.
Multiple GitHub Accounts
Issue: You need separate SSH keys for work and personal accounts.
Solution: Configure host aliases in ~/.ssh/config:
` Host github.com HostName github.com User git IdentityFile ~/.ssh/ided25519personal
Host github-work HostName github.com User git IdentityFile ~/.ssh/ided25519work `
Clone work repos with git clone git@github-work:company/repo.git
Related Processes
Once SSH authentication works, these related tasks become relevant for your software development process.
Managing Multiple SSH Keys
Developers working with multiple GitHub accounts, GitLab, or Bitbucket need separate key pairs. The SSH config file routes connections to the correct identity based on host aliases.
Rotating SSH Keys
Security best practice: rotate keys annually or when team members leave. Generate new key, add to GitHub, test, then remove old key from both local machine and GitHub settings.
SSH with GitHub Enterprise
Enterprise instances use different hostnames. Adjust your SSH config to point IdentityFile to the correct key for your company’s GitHub Enterprise URL.
Using SSH for GitHub Actions
GitHub Actions workflows can use deploy keys or SSH keys stored as repository secrets for continuous integration tasks. Add your private key as a secret, configure the workflow to load it into ssh-agent.
Deploy Keys vs User Keys
Deploy keys grant access to a single repository. User SSH keys grant access to all repositories you can access. For continuous deployment pipelines, deploy keys provide tighter security boundaries.
Converting Existing Repositories
Already cloned repos using HTTPS need their remote URL updated. Run git remote set-url origin git@github.com:username/repo.git in each repository to switch to SSH authentication.
FAQ on How To Add SSH Key To GitHub
What is an SSH key and why do I need one for GitHub?
An SSH key is a cryptographic credential that authenticates your identity without passwords. GitHub uses it to verify your machine during Git operations like clone, push, and pull. Faster workflow, stronger security than HTTPS authentication.
Where are SSH keys stored on my computer?
SSH keys live in the ~/.ssh directory. On macOS and Linux, that is /Users/username/.ssh or /home/username/.ssh. Windows stores them in C:Usersusername.ssh. The folder contains your private key and public key files.
What is the difference between Ed25519 and RSA keys?
Ed25519 uses elliptic curve cryptography, producing smaller keys with faster authentication. RSA is older but still secure at 4096 bits. GitHub recommends Ed25519 for new keys. RSA works if your system lacks Ed25519 support.
Can I use the same SSH key for multiple GitHub accounts?
No. GitHub requires unique keys per account. Create separate key pairs for work and personal accounts, then configure your ~/.ssh/config file with host aliases to route connections to the correct identity file.
What does “Permission denied (publickey)” mean?
GitHub cannot find a valid key for authentication. Common causes: ssh-agent not running, key not added to agent, wrong key uploaded to GitHub, or incorrect git config settings. Run ssh-add -l to check loaded keys.
Do I need a passphrase for my SSH key?
Optional but recommended. A passphrase encrypts your private key, adding protection if someone accesses your machine. The ssh-agent remembers it during your session, so you only type it once after login.
How do I switch an existing repository from HTTPS to SSH?
Run git remote set-url origin git@github.com:username/repo.git in your repository folder. Verify with git remote -v. The URL should now start with git@github.com: instead of https://.
Can I add multiple SSH keys to one GitHub account?
Yes. Add separate keys for each device: laptop, desktop, work machine. Navigate to GitHub Settings > SSH and GPG keys and click New SSH key for each. Descriptive titles help identify which key belongs to which device.
How do I test if my SSH connection to GitHub works?
Run ssh -T git@github.com in your terminal. Success returns "Hi username! You've successfully authenticated." The warning about no shell access is normal. GitHub only allows Git protocol operations, not terminal sessions.
What is the difference between authentication and signing keys?
Authentication keys verify your identity for Git operations. Signing keys verify commit authorship, adding “Verified” badges to your commits. You can register the same key for both purposes in GitHub’s SSH settings.
Conclusion
You now know how to add SSH key to GitHub and can authenticate Git operations without typing passwords.
The setup takes minutes but saves hours over time. Every clone, push, and pull runs through your encrypted connection automatically.
Your private key stays on your machine. Your public key lives on GitHub. The ssh-agent handles the handshake.
From here, consider integrating SSH authentication into your build pipeline for automated deployments. Teams using DevOps practices rely on SSH keys for secure repository access across CI/CD workflows.
Rotate your keys periodically. Use passphrases for extra protection. Keep your terminal commands handy for new machines.
Passwordless authentication is the standard for modern source control. Your workflow just got faster.
- Android App Drawer vs Home Screen: Differences Explained - April 16, 2026
- 7 Things to Know Before Buying Refurbished Servers in 2026 - April 16, 2026
- iPhone Parental Controls: Complete Guide - April 15, 2026







