Learning Objectives

Installing Git

  1. Install git:

  2. Create an account on GitHub: https://github.com/

    • A free plan is fine. Use the same email address you used above.
    • When you choose your username, remember that you might use this for professional purposes. So I would recommend something related to your name (e.g. my handle is “dcgerard”). I would recommend against something like “david_awesome_david_yolo_hahaha”.
  3. Tell git your name and email address. Open up a terminal and type:

    git config --global user.name "YOUR FULL NAME"
    git config --global user.email "YOUR EMAIL ADDRESS"

    If you are worried about email privacy, then use “<username>@users.noreply.github.com” as your email address (where you have replaced <username> with your GitHub username), then follow the instructions here to make your email address private on GitHub.

  4. Choose your favorite editor to be your default

    • Nano (a simple text editor):

      git config --global core.editor "nano -w"
    • Notepad (Windows only):

      git config --global core.editor "c:/Windows/System32/notepad.exe"
    • Emacs (for the brave) if it is already installed:

      git config --global core.editor "emacs"

Authentication

Generate Key Pair on R Studio

  • R Studio makes it easy to generate a key pair.

  • Check to see if you already have an SSH key pair by running the following in R

    file.exists("~/.ssh/id_rsa.pub")

    It will return FALSE if you do not have a key pair.

  • Open up Tools > Global Options… > Git/SVN.

  • If you do not have an SSH key pair, then click on “Create SSH Key…” and follow the prompts.

    Create RSA Key

  • Click on “View public key”

    View Public Key

  • Copy the entire text that shows up. This is your public key.

  • Go to Add Public Key to GitHub to continue authentication setup.

Generate Key Pair on the Terminal

  • If the R Studio pipeline does not work, then try generating your key pair on the terminal with the following instructions.

Check for existing SSH Keys

  • In the terminal run

    ls -al ~/.ssh
  • This will say something like “ls: cannot access ‘/c/Users/Vlad Dracula/.ssh’: No such file or directory” if you don’t have any public/private key pairs.

  • This will list out files names like “id_rsa.pub”, “id_ecdsa.pub”, or “id_ed25519.pub” if you do have a public/private key pair.

Generate a new SSH key

  • If you do have an SSH key, go to the next section (“Add an SSH key to the ssh-agent”)

  • If you don’t have an SSH key, follow the below steps.

  • In the terminal, run

    ssh-keygen -t ed25519 -C "your_email@example.com"
  • Press enter if prompted where to save the key to accept the default location.

  • At the prompt, type a password that you can remember.

Add an SSH key to the ssh-agent

  1. In the terminal, run the following to start the ssh-agent in the background.

    eval "$(ssh-agent -s)"
  2. In the terminal, run the following to add your SSH private key to the ssh-agent:

    ssh-add ~/.ssh/id_ed25519

Copy Public Key

  1. Run the following in the terminal to show the contents of “id_ed25519.pub”.

    cat ~/.ssh/id_ed25519.pub
  2. Highlight the output using your mouse and copy the contents.

Add Public Key to GitHub

  1. On GitHub, in the upper right corner, click on your profile photo and click on “Settings”

    GitHub Account Settings Menu

  2. On the left sidebar, click on “SSH and GPG keys”

    SSH and GPG Keys

  3. Click on “New SSH key”

    SSH and GPG Keys

  4. In the title field, choose a descriptive title, like “Personal Laptop”.

  5. Paste your key into the “Key” field.

  6. Click “Add SSH key” and confirm your GitHub password.

Test to see if it worked

  1. Enter the following in the terminal:

    ssh -T git@github.com
  2. Type “yes” if prompted to continue connecting.

  3. You are successful if you see something like

    Hi dcgerard! You've successfully authenticated, but GitHub does not provide shell access.