DEV Community

Sarah Bartley Dye
Sarah Bartley Dye

Posted on

Connecting Your Computer to GitHub - Part One

You now have a brand-new GitHub account. Let’s start using it. The next lesson in Skillcrush 105 is about connecting your GitHub account to your computer, allowing you to access any repository from the command line.

Today’s lesson is about connecting your computer to your GitHub account. It also introduces forking, cloning, and pushing repos. There’s a lot of information in this lesson, so I’m splitting it into multiple posts.

Part one will focus on SSH and using it to connect to GitHub. The next few posts will concentrate on everything you can do after GitHub has been set up. This will guide you through steps such as forking, cloning, and modifying a repository.

Why would I want to connect my computer to GitHub?

Accessing any GitHub repo from the command line is a highly desired skill for many employers. Many job postings will even put GitHub as one of their requirements for a position. When I began interviewing for jobs, many employers mentioned that they use GitHub or an alternative to GitHub for their code repositories.

What makes this a desired skill is that it makes it so much easier for developers to work with each other on projects. They can stay up to date on the files and share what they are working on with team members. Everyone on a developer team can use some of the git commands you’ve been learning to push and pull information to the repo, so the entire team is up to date on what is happening in the project code.

This makes GitHub very similar to Google Drive. Google Drive makes it possible for team members to share each other’s writing, make copies, and comment on files. As long as team members have a link that grants them access to edit and make comments, they can work on the same project from anywhere in the world.

Another perk of having this connection is that GitHub is another great place for backing up any projects. Developers can push changes to GitHub. If something happens to their computer and they can lose their files, they can download or pull code from GitHub from the latest version they were working on.

GitHub comes in handy in future Skillcrush lessons. If Skillcrush students wanted to learn WordPress next, GitHub was frequently mentioned in these lessons for backing up site files and getting access to project files a client might have. Any developers who want to freelance in the future will be seeing SSH and using the commands in this lesson.

What is SSH?

Before you can connect your computer to GitHub, Skillcrush takes a few minutes to talk about Secure Shell (SSH). SSH is going to play an important part in working with GitHub, so you’ll be using SSH not only for connecting your repo, but with forking and cloning repos you will be doing in part two. Secure Shell (SSH) is “the protocol that makes a shared connection between computers”.

Skillcrush says that this is what creates the connection your computer and GitHub will share. To create this connection, Secure Shell uses an SSH helper program that is built into the command line. Secure Shell might sound very fancy, but the best news about SSH is that you just need to set it up once.

After it is set up, you’ll be able to get any content from GitHub you want as long as it is on your computer. However, SSH is specific to every computer, so if you get a brand new computer, you’ll need to set up SSH again. Skillcrush reassures students that SSH is very secure.

Secure Shell encrypts your data or changes it into a secret code that only the computer and GitHub understand. Secure Shell does this by sharing an SSH key pair between your computer and your GitHub account. This lesson tells students that the SSH key is like an answer key for a test.

The SSH key lets the computer and GitHub change data into a secret code, then revert the code into original data. That means a computer can turn data into a secret code. The code gets sent to GitHub. GitHub receives the code and will turn the code into the original data.

How to Use Secure Shell (SSH) to Connect to Your Computer to GitHub

Now that students know a little bit about SSH and how it works, they are ready to use it to create a connection between the computer and GitHub. It doesn’t matter if you have a PC or a Mac for this challenge. Skillcrush provides both, depending on what type of computer you have.

Step One: Open your command line. PC users will open Git Bash. Mac users will open the terminal.

Regardless of what command line you use, type cd ~ to go to your home directory. Type pwd command to check if you are in your home directory. You will know you are in your home directory if you see the following:

  • /c/Users/Sarah (PC)
  • /users/Sarah (Mac)

Step Two: You are going to create an SSH directory. Type mkdir .ssh command into the command line. Use the cd command after that to go into the new directory you made.

Step Three: Now create your SSH key pair. Type the following command in your command line. Skillcrush reminds students to replace the your_email placeholder with your email.

ssh-keygen -t rsa -C "your_email@your_domain.com"  in the command line.
Enter fullscreen mode Exit fullscreen mode

Step Four: After you press the Enter key, the computer will receive a message saying something like this:

Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

This message is just checking to see if the location to save the key pair is correct. This location will work just fine, so press Enter.

Step Five: The computer will ask you for a passphrase. Type in the phrase you want. As you type your passphrase, you won’t see anything on the command line.

Computers do this for security purposes. Save your passphrase somewhere safe. Press Enter when you are ready.

The computer will finish creating your SSH keys. Your key pairs are ready. Let's add the keys to the SSH agent.

Your computer will use this key every time you need to communicate with the SSH.

  • PC user = You will see a message on the command line such as agent pid XXXX. When you see this message, you will need to put the following message:
eval “$(ssh agent -s)”
Enter fullscreen mode Exit fullscreen mode
  • Mac user = You will need to type the following message in the terminal. You will need to run this command every time you update your operating system or restart your computer to autofill the passphrase when pushing things to GitHub.
ssh-add —aple-use-keychain ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Step Six: We need to copy-paste the public key from the command line. You can copy the public key with the code below. You won’t see any response letting you know the code has been copied, but your SSH key has been copied.

  • PC Users = You will use the command below:
clip < ~/.ssh/id_rsa.pub 
Enter fullscreen mode Exit fullscreen mode
  • Mac Users = You will use the command below.
pbcopy < ~/.ssh/id_rsa.pub.
Enter fullscreen mode Exit fullscreen mode

Step Seven: Go back to GitHub. Click the profile icon in the top right corner. Click on settings. Look for SSH and GPG keys on the left sidebar menu and click them.

Click New SSH Key in the top right corner. Name your key. Paste the key you copied earlier here.

The key will be made up of letters, numbers, and characters. Click Add SSH Key Button when you are done.

Note: Naming your key is very important because keys are connected to specific computers. So be descriptive with the name as much as possible.

Step Eight: Go back to the command line. Type the following command in Git Bash/Terminal to check if the computer is connected to GitHub.

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

You will get a message like this in the command line below. Ignore this message. It is just saying that you don’t have full access to GitHub’s server.

The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?
Enter fullscreen mode Exit fullscreen mode

Type yes and press Enter. You will get another message that looks like this.

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Congratulations! You are now authenticated with GitHub. That means your computer and GitHub are connected.

Top comments (0)