Generate SSH Keys for your GitHub Accounts

Ryan Harris
InstructorRyan Harris
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

In some cases, you may have multiple GitHub accounts that you need to interact with from the same system. For example, you could have an account for work and another for personal projects, but you don't want to re-authenticate each time you switch between then. By using public SSH keys for each account, you can eliminate this part of the process.

In this lesson, we will create two SSH keys in our terminal using ssh-keygen , copy them to our clipboard using pbcopy and then add them to our respective GitHub accounts.

Commands we'll be using include:

  • ssh-keygen
  • ls
  • pbcopy

Instructor: [0:00] Let's start by creating our personal key using the ssh-keygen command and pass in a few options. -T is for the type. -B is for the number of bits we're going to use. -C is to add a comment. In this case, it's going to be our email address, ryan@ryanharris.dev.

[0:18] Here we're being prompted to choose a file name. We're going to use the default, IDRSA and hit enter. We're going to choose an empty pass phrase as well by hitting enter twice. As you can see here, we've created a new directory called .ssh. Let's cd.ssh into that directory.

[0:37] If we list everything out you can see our new public and private key. Now we want to do the same thing for our work account. We're going to run ssh-keygen again. However, in this case we're going to update the email address to ryan@egghead.io and hit enter.

[0:57] This time when we're prompted, we're actually going to change the name of the file we want to use and do id_rsa_work. We're going to use an empty passphrase again and hit enter twice.

[1:09] Now if we list out this directory, you can see we have another public key as well as another private key. Now that we've generated these keys, we need to associate them with our respective GitHub accounts. We're going to do that by running pbcopy, which is going to copy our public key from .ssh/id_rsa.pub to our clipboard.

[1:33] Then here in GitHub, we're going to say we want to create a new SSH key. We'll say, "Ryan personal." Here, we're going to hit control-V or command-V to paste in the key that we created here on our system. As you can see, this is the comment we added with the -c flag.

[1:52] Now if we save it, we've now associated that key from our local system to our GitHub account. For our work account, we would do exactly the same thing.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today