Authenticate GitHub Using SSH to Push Code
26 May 2026 / 2 min read
Table Of Content
# Generate an SSH Key
Make sure the openssh package is installed.
If you don’t already have an SSH key, generate a new one using the secure Ed25519 algorithm:
ssh-keygen -t ed25519 -C "your_email@example.com"When prompted to “Enter a file in which to save the key,” press Enter to accept the default location (~/.ssh/id_ed25519). You can also choose to add a passphrase for an extra layer of security.
# Add Public Key to GitHub
Copy the public key generated earlier (the file ending with .pub).
cat ~/.ssh/id_ed25519.pub Go to github.com and log in.
In the upper-right corner of any page, click your profile photo, then click Settings.
In the left sidebar, click SSH and GPG keys.
Click the New SSH key button.
In the Title field, add a descriptive label for the new key (e.g., “Work Thinkpad”).
Select Authentication Key as the key type.
Paste your public key into the Key field.
Click Add SSH key.
# Test the Connection
To ensure everything is configured correctly, test your connection to GitHub:
ssh -T git@github.comYou should then receive a successful authentication message:
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.# Pushing Code
On your Git repository directory, check your current remote URL:
git remote -vIt will probably show in HTTPS format:
origin https://github.com/your_username/your_repo.git (fetch)
origin https://github.com/your_username/your_repo.git (push)Change it to SSH:
git remote set-url origin git@github.com:your_username/your_repo.gitVerify the change, now it is ready to use:
git add .
git commit -m "Initial commit"
git push -u origin main