When working on multiple environments, you might run into this error when pushing to GitHub:
identity_sign: private key /home/hastycode-andreh/.ssh/id_ed25519 contents do not match public
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
This usually happens when:
- You already have an SSH key (
id_ed25519
) used for something else (like a server), and - You're trying to use GitHub with that same key, but GitHub doesn't recognize it.
π‘ Solution: Create a dedicated SSH key for GitHub, and tell your system to use it only for GitHub connections.
β Step 1: Generate a New SSH Key for GitHub
Letβs create a new key and name it something distinct, like id_ed25519_github
.
ssh-keygen -t ed25519 -C "your_email@example.com"
Youβll see:
Enter file in which to save the key (/home/your-name/.ssh/id_ed25519):
Respond with:
/home/hastycode-andreh/.ssh/id_ed25519_github
This generates two files:
-
~/.ssh/id_ed25519_github
(private key) -
~/.ssh/id_ed25519_github.pub
(public key)
β Step 2: Add the Key to Your SSH Agent
Start the SSH agent if it's not already running:
eval "$(ssh-agent -s)"
Then add your new GitHub key:
ssh-add ~/.ssh/id_ed25519_github
β Step 3: Add Your Public Key to GitHub
- Copy your public key:
cat ~/.ssh/id_ed25519_github.pub
Go to GitHub SSH keys page
Click "New SSH Key", give it a name like βAndreh Laptop GitHub Keyβ, and paste the key.
β Step 4: Create a Custom SSH Config for GitHub
Now, tell your system to use the GitHub key only when talking to GitHub.
Edit or create your SSH config file:
nano ~/.ssh/config
Add this:
# GitHub account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
π‘ This ensures your original server SSH key is untouched.
β Step 5: Test the SSH Connection
Letβs verify everything is working:
ssh -T git@github.com
Expected output:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
Perfect! π You're now pushing to GitHub securely using a separate SSH key.
β Optional: Clean Up Your SSH Agent (If Needed)
If your old key is causing conflicts, you can remove it:
ssh-add -d ~/.ssh/id_ed25519
This ensures your system prioritizes the GitHub key when needed.
π§ Bonus: Multiple GitHub Accounts?
If you're juggling both personal and work GitHub accounts, you can add an alias in your SSH config:
# Personal GitHub
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
# Work GitHub
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Then in Git remotes, use the alias:
git remote set-url origin git@github.com-personal:username/repo.git
π Wrapping Up
This setup gives you a clean and flexible way to manage multiple SSH keys on the same machine β no more conflicts between GitHub and your server environments.
Top comments (0)