Login to GitHub on macOS Using SSH Key
This guide will show you how to create an SSH key on your computer and add it to GitHub. By doing this, you can establish a secure and convenient connection between your computer and GitHub, making it easier to clone, pull, and push repositories without having to enter your password every time.
1. Generate an SSH Key (if you don’t already have one)
ssh-keygen -t ed25519 -C "your_email@example.com"
- When asked where to save the file, you can press Enter to use the default location: ~/.ssh/id_ed25519.
- Set a passphrase (optional, but recommended).
Add the key to the ssh-agent (optional):
eval "$(ssh-agent -s)" ssh-add --apple-use-keychain ~/.ssh/id_ed25519
2. Add the SSH Key to GitHub
Copy your SSH public key:
cat ~/.ssh/id_ed25519.pub
Copy the entire output.
Go to GitHub → Settings → SSH and GPG keys → New SSH key, then paste the key.
3. Change Remote from HTTPS to SSH
Check your current remote:
git remote -v
If it shows HTTPS, for example:
https://github.com/username/repo.git
Change it to SSH:
git remote set-url origin git@github.com:username/repo.git
4. Test the Connection
ssh -T git@github.com
If successful, you will see a message like:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Now your GitHub is set up to use SSH on macOS, making your workflow more secure and seamless.