Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without providing your username and password at each commit or push as well, which can save you a lot of time. This tutorial will walk you through setting up an SSH key pair on your server, and GitHub.
Generating a key pair via SSH
- Login to your terminal via SSH
- Generate a key pair by running the following command, substituting in your GitHub email address between the quotes
ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
- When you’re prompted to “Enter a file in which to save the key,” press Enter to save it in the default location. If you wish to use a different location, you can provide the path to be used here as well.
- At the prompt, type a secure passphrase that will be used when your key is authenticating, and confirm it
Congratulations! You now know how to generate an SSH key pair. Now we are going to walk you through the steps needed to supply your public key to GitHub for authentication.
Adding your public key to GitHub
- View your public key by running the following command, substituting the file path with the one you used in the previous tutorial if you did not use the default location
cat ~/ssh/id_rsa.pub
- Select and copy the entire key to your clipboard
- Login to your GitHub account
- In the upper-right corner the GitHub website, click your profile photo, then click Settings.
- On the left hand side, select SSH and GPG Keys.
- Select New SSH key or Add SSH key.
- In the “Title” field, add a label for the new key.
- Paste your key into the “Key” field.
- Select Add SSH key.
- If prompted, confirm your GitHub password.
Congratulations! You now know how to set up your SSH key pair on your server, and use your public key to connect via SSH to GitHub.
SIGNUP FOR
BOLDGRID CENTRAL
200+ Design Templates + 1 Kick-ass SuperTheme
6 WordPress Plugins + 2 Essential Services
Everything you need to build and manage WordPress websites in one Central place.
Charles says:
Hello
For me the right command is
cat ~/.ssh/id_rsa.pub
Brandon says:
Hi Charles,
You are correct, this is the command you would use to view your Public Key.
MICHAEL says:
Hello I need your help am trying to create my SSH key but am not going through .What procedure do I need to take ?
Brandon says:
Hi Michael,
Thanks for reaching out. What issues/errors are you running into while attempting to create your SSH keys?