SSH, it’s going to connect to GitHub
As of November 2021, GitHub started to require SSH keys to access your account. While this does provide better security access, it first managed to confuse new programmers completely and second, make it more challenging to access multiple GitHub accounts on a single computer, or from multiple computers. Here, we will walk through the sets of getting a setting on an SSH key so you can access your various accounts from multiple computers. I promise it is easier than it sounds (at least on a Mac).
Before we get started, please do this before you start cloning from repositories; it will save you a headache.
1. Get an SSH key
SSH stands for Secure Shell Protocol. This is a way for operating network services to become secure over insecure networks.
Open your terminal
ssh-keygen -t ed25519 -C "email@example.com"
You’ll get back something that looks something like this.
This will generate a public and private key-value pair that GitHub will be able to check against. To see this newly generated pair, you can go to ~/.ssh
You should see an
If you don’t see a config file, that’s okay; we will create one later.
Do you see the connection? The document is generated using the -t the output_file provided, the ed25519. If you run:
## you will get the output of what is in the file
ssh-ed25519 $$$$$$$$$$$$A_NICE_LONG_ENCODED_STRING$$$$$$$$$$$$$$ firstname.lastname@example.org
I do recommend changing the file names to reflect the account you will be using this key on. You will see more about this later on. If you do update this now, make sure you update both the regular private file and the public file. You want them to match. The one that reads id_ed25515 is considered a private key, and the one ending .pub is the public key. You will need the public key shortly.
2. Add your SSH key to your account.
Log into the GitHub account you are going to need access to. Go to your profile and settings.
Then find the section titled “SSH and GPG keys”.
On this page, you will click the button “ New SSH key” or “Add SSH key.”
You will be taken to this next page.
I recommend using a descriptive phrase for the computer/laptop/machine you use to access this account.
Within key, in the contents on the .pub file, you will be using as your key. Then “Add SSH Key”. You may be asked to reconfirm your password at this time.
Now, whenever you clone a repo, make sure you have the SSH clone copied.
3. Add Another
So you may recall, back when we created our first key, you included ed25519. Did you think it was just the name used on the generated file? Not so fast.
This is a cryptographic solution brought to you by Edwards-curve Digital Signature Algorithm, (EdDSA). It is a way to encrypt your access code. It’s been around since about 2014, so it’s possible by the time you are reading this, a new standard encryption code is being recommended. The ed25519 is what is recommended by GitHub currently.
But how does this affect you? Why am I bringing it up? For the most part, it doesn’t, other than to say, verify with your Security Officer, GitHub, or the internet, in general, to verify your information is being securely held. You will be able to use this code on any number of ssh generations as this will always generate a new and unique code even given the exact same output; HOWEVER, to avoid confusion when creating multiple keys, I recommend changing the file name to reflect the associated GitHub account.
So, you will repeat steps two and three. There is where things can get a little tricky. You can have multiple ssh keys on a single account, (this may require additional variables to be included in your config file), or you have multiple accounts on a single computer. You may have a work computer and a home computer but need access to the same account, which we will see in step 4.
4. Update Internal
Remember the config file I mentioned before? Well, you will now!
Let’s go back to the ~/.ssh folder. If you have a config file, open it. If you don’t
You can use VIM, but I prefer to use open the file in TextEdit.
There are four essential lines you will need
Uh? Okay, let’s break it down, bottom-up.
IdentityFile, this is the path the private ssh key that pairs with the pub ssh key you added to your account.
User, this is the username on your GitHub account, not your email, but your username.
HostName, the URL we pass this information to. This will always be github.com unless you are using this SSH key for a different system.
Host, this is a tricky one. It seems straightforward, but not quite. “Why?” you say? Do you know that funny part at the beginning of your clone URL?
Yeah, the part that comes before the colon? That is what drives the host time. Since you will have multiple accounts on this computer, you cannot use the same Host over again, or you will get a lot of failure notices when you go to push your content.
Whichever account will be your primary, keep the github.com; for your secondary, tertiary, etc., go ahead and add a dash and an identifier. So your Host will look something like this:
Save your changes, and you should be able to Clone and Push to any repos you need!
Notes on Clone
If you use my recommendation above, ANY clones you do, you will need to include your -identifier to the clone.
If you do not include this, it will try to pull from your primary account, and you will get a lot of errors.
Well, that’s it! You did it! Give yourself a high-five, do a happy dance and stay safe. Happy coding.
Sources / My journey:
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
If you don't already have an SSH key, you must generate a new SSH key to use for authentication. If you're unsure…
Adding a new SSH key to your GitHub account - GitHub Docs
Before adding a new SSH key to your account on your GitHub Enterprise Server instance, you should have: After adding a…
Can I have multiple ssh keys in my .ssh folder?
Thanks for contributing an answer to Super User! Please be sure to answer the question. Provide details and share your…