I got a new laptop and had to go through the pain for setting up my entire dev environment from scratch. After hours of downloading and installing tools I was ready to go. I tried to pull one of my old repos from GitHub and I got the good ol'
Permission denied (publickey). That really sucked, not gonna lie, completely forgot about GitHub's SSH keys. Which is why I decided to write this post today.
I remember the first day I ran into this problem, it took me forever to find a solution. I hope this would make it a little easier for someone out there to get up and running in no time.
We'd first start by setting up our own public/private key pair set. This can use either DSA or RSA. Which means basically any key we set up will work, most systems use
First, we'd want to enter the
.ssh directory. Open the terminal and run this command:
Next, we need to generate our own personalised ssh key, by running this command:
Now that our key has been generated, we'll need to copy it.
Note: the text that shows up after the command has been run is not what we need.
To copy the key, we'll need to run a command that is specific to whatever OS (and in some cases terminal) is running on the system so pick the one that fits your need.
Windows (Cygwin/Git Bash):
cat id_rsa.pub | clip
Get-Content id_rsa.pub | Set-Clipboard
cat id_rsa.pub | pbcopy
cat id_rsa.pub | xclip
Next, we head over to GitHub to add the key to our account.
When we get there, we log in (if you aren't already logged in). Once logged we're logged in we'll see the profile icon in the top right corner of the page, click on it. It will open a menu like this:
Go ahead and select the Settings option.
Now we're in the SSH and GPG keys section, we can now add our new SSH key which we copied earlier.
Top right on the page you'll see a button that says New SSH Key, click on it.
We'll get a page like this:
In the Title field we'll give the SSH key a good description so we can know which device it belongs too. I normal use the make and year of the device, e.g. MacBook Pro 2020.
And in the Key field/textarea, that's where we paste the key we copied. Once we've done this, we can now hit the Add SSH Key button.
We now need to configure our
Open the terminal and run these commands.
To add our username to our git config we'll run:
git config --global user.name "example"
"example" with your own username.
To add our email to our git config we'll run:
git config --global user.email email@example.com
firstname.lastname@example.org with your own email.
Once this is done, restart the terminal and we should be good to go to.
I hope this was of help 😊.
PS: I know some of you use Personal Access Tokens, maybe I'll make a post for those too