TLDR
ssh-keygen -t ed25519 -C "email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
# Copy public key
# Create & Paste into GitHub deploy keys
git clone git@github.com:USER/foo.git
I often forget how to set up GitHub ssh keys for deployment. Here is a quick guide on how to set it up.
All of these commands can be found on GitHub's guides but spread around many pages. This guide consolidates them
1. Create your unique ssh key pair.
It's recommended to use the ed25519 algorithm instead of rsa nowadays.
Note: the email doesn't do anything. It's just for labeling.
ssh-keygen -t ed25519 -C "myemail@example.com"
If you already have a pair of ed25519 keys you may skip this step.
This will prompt you to save the key to a location. Using the default location is fine.
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/me/.ssh/id_ed25519)
Just press enter.
Create a passphrase if needed. Otherwise, just press enter.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter the same passphrase again: [Type passphrase again]
2. Start ssh-agent
eval "$(ssh-agent -s)"
Why use eval? ssh-agent -s
generates the bash code to run. Then, we use eval to run that code.
3. Add the key to your ssh-agent
ssh-add ~/.ssh/id_ed25519
4. Copy the public key
cat ~/.ssh/id_ed25519.pub
Copy output public key
5. Create Github deploy key
Your Repo > Settings > Deploy Keys
Paste your public key into your new deploy key for your repo.
6. Pull from your GitHub Repo
Code Dropdown > SSH Tab > Copy URL
git clone git@github.com:USER/foo.git
And you're done!
References
Github: Generating a new SSH key and adding it to the ssh-agent
Top comments (0)