Say Goodbye to Passwords: Secure Your GitHub with SSH Keys
🐙Learn how to set up SSH keys to make your GitHub experience smoother, more secure, and password-free.
Ever felt like you were in battle over remembering passwords? Yeah, we've all been there. The superhero solution for secure connections to GitHub is SSH keys!
📜Introduction
SSH Keys are important when it comes to pushing your content on github securely. This document details the steps to be followed to generate SSH keys , add them onto your github account and finally configuring your git repo to use these newly added keys for secure access.
🗝️Why SSH Keys?
SSH keys are like a super secure digital handshake. They’re used to encrypt the connection between your computer and GitHub, instead of using a password. Not having to type your password means you can push your code to GitHub more quickly. Also, no more trying to remember what on earth that 20-character password you came up with at 2 am last night actually was. Let’s get started!
🔑Generating Your SSH Keypair
First things first, open up your terminal. This is where we will be doing the magic. We're going to use a command line tool which generates for you a special keypair. Copy and paste this line into your terminal:
[mike@localhost ~]$ ssh-keygen -t rsa -b 4096 -C "a++++@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mike/.ssh/id_rsa):
Created directory '/home/mike/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mike/.ssh/id_rsa
Your public key has been saved in /home/mike/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:rsfOHbsryr4wGjGMSCt***********RmxVfxRP4 a++++@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
| .o.o=oo .ooo|
| . .+o* . + |
| . ooo+oo o|
|oo. . o +o .|
|+.= . o S . E|
|.. + o . |
| . o .. . |
| o + o+. o |
| . .*=o.=o |
+----[SHA256]-----+
Hold on! What does all this mean?
ssh-keygen
: This is the command that will actually generate the key pair.
-t rsa
: This tells the command that we want to use the rsa encryption type (a strong choice).
-b 4096
: This sets the key size to 4096 bits (more bits = more secure).
-C "
your_email@example.com
"
: This is your email address. You'll use the email address associated with your new GitHub account. Press Enter. Follow any prompts you may receive.
You'll be asked to choose a location in which to save the key. The default is typically just fine but you can put it somewhere else if you want. Then, you might be asked for a passphrase. This is an optional extra step of security; think of it like a PIN number for your key. Your call!
The terminal will spit out some funky looking text— that's your key! It looks strange, but it's essentially the thing you'll paste in order to create secure connections.
🔐Adding the Key to Your Keychain (SSH Agent)
Let’s now add your key into a special program, it is like a secured keychain where we are going to put our key on it and have it ready when using it.Copy and paste this line into your terminal:
[mike@localhost ~]$ eval "$(ssh-agent -s)"
Agent pid 2740
Then, add your key to the agent with this line:
[mike@localhost ~]$ ssh-add ~/.ssh/id_rsa
Identity added: /home/mike/.ssh/id_rsa (a++++@gmail.com)
➕Adding the SSH Key to GitHub Account
We need to copy the public part of your keypair (think of it as the half you give to GitHub). Here's the magic code to copy it:
[mike@localhost ~]$ cat ~/.ssh/id_rsa.pub
This will display your key in terminal. Copy it (usually you have to sublimate it and press crtl+c) to your clipboard.
Now, Go to GitHub, navigate to Settings > SSH and GPG keys > New SSH key*,* and paste the key.
🧪Testing the SSH Connection
Want to see if your shiny new key works? In your terminal, type:
ssh -T git@github.com
If you see a message that says something like welcome followed by your username, you're in business!
Congrats! - You have just setup your SSH keys to connect securely and without having to type your username/password each time to GitHub. Now go there and push it!
📚Summary
SSH setup for GitHub increases the security of your repository interactions. Doing so involves creating an SSH key pair, adding it to the SSH agent, adding it to GitHub, testing your connection, configuring a local repository, and securely pushing content to GitHub. Learn how in this brief and practical guide to securing your GitHub workflow.