Skip to content

Part I ➝ Setting up SSH keys locally (MacOS) #2

@jimmylee

Description

@jimmylee

What will I know after finishing this?

You will learn the following things

  • You're going to be to commit code to a GitHub repository from your command line.
  • You're going to be able to follow the rest of the setup steps.

If you have any questions, don't hesitate to ask!

Setting up your SSH keys

We're going to generate a key on your computer that lets you push and pull code from GitHub.

  1. Open iTerm, install it if you don't have.
  2. Run the following command:
mkdir ~/.ssh
  1. That will make the directory for your key if it doesn't exist, if it does just ignore the error.
  2. Run this command next to generate your key, remember to put YOUR GitHub e-mail in the quotes:
ssh-keygen -t ed25519 -C "[email protected]"
  1. You should see the following:
>Generating public/private ed25519 key pair.
>Enter a file in which to save the key (/Users/your_user_name/.ssh/id_ed25519):
  1. Just press enter, which will save the file in the default directory (the one you created/validated in step 2)
  2. You might get this prompt:
>Enter passphrase (empty for no passphrase):
  1. Just press enter when you see this prompt. You don't need a password.

And viola! You have finished the hardest step. Now you have a unique key sitting on your computer doing absolutely nothing.

Add your keys to your local agent

  1. Run this command:
eval "$(ssh-agent -s)"
  1. Next run this command to give this agent the key:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
  1. Now your agent has the key, but we will want to make sure we never have to do these steps again, so we're going to create a config file and add some stuff to it.
  2. To create a file, run the following command:
touch ~/.ssh/config

Touch is the command to create a file with 0kb. That means an empty file. Touch is a "program" that your computer comes with, the second argument ~/.ssh/config is the path you are going to put the file. In this case you want it in your .ssh folder.

  1. Next use the following command to open the file:
open ~/.ssh/config
  1. Next copy and paste the following into the file:
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
  1. Save the file.

And you're done with the second part. If you did everything correctly, as long as you have this computer, you will never have to do these things again until you get a new computer.

There is the chance that you leak this key to the public. You would probably have to start over if that happened, so just don't go around sharing this information.

Add your keys to GitHub

You have created your key locally, but your GitHub account needs to know the public replica of your key so when you try to authenticate/sign-in/log-in it knows its you!

  1. First we need to run this command, this will copy your key so we can paste it later on github.com
pbcopy < ~/.ssh/id_ed25519.pub
  1. Notice that we didn't give GitHub your private key, but the one that ends in .pub, GitHub never will get to see your private key.
  2. Go to Github.com and click 'Settings'

Screen Shot 2022-07-29 at 10 25 02 PM

  1. In sidebar on the left side of the page, click ‘SSH and GPG keys’

Screen Shot 2022-07-29 at 10 25 44 PM

  1. Click ‘New SSH key’

Screen Shot 2022-07-29 at 10 26 29 PM

  1. Give it a name, it can be anything
  2. In the ‘Key’ field, paste the copied content of your SSH public key (you copied it step 1, you can run the command again if you lost it)
  3. Click ‘Add SSH key’. You may have to enter your password.

Now you're done. Time to move on to some other parts.

Metadata

Metadata

Assignees

Labels

DocumentationDocumentation for developers at Internet Development Studio

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions