Set up git authentication

Git does not allow password authentication for pushing/pulling your repositories. Instead, we will use an ssh public key to authenticate your identity.

In this method of authentication you generate a public key and a private key. The private key stays on your computer (in this case your Jetstream instance) and the public key is given to 3rd parties who will want to verify your identity (in this case GitHub).

When you attempt to login to GitHub a program called SSH tests to see if your computer has the matching private key.

Create a GitHub Account

If you do not have a GitHub account, please go to github.com and create an account.

Generate a ssh key pair

IF YOU KNOW WHAT YOU ARE DOING AND PREFER TO USE A PERSONAL ACCESS TOKEN AND HTTPS ACCESS THAT IS FINE, DO IT YOUR WAY, OTHERWISE…

You can either generate a ssh key pair at the command line or in Rstudio. For this class, we will use Rstudio.

  1. Open Rstudio on your Jetstream instance. (Or laptop if you are not enrolled in BIS180L)
  2. Choose Tools > Global options from the pull-down menu.
  3. From the options box, click on Git/Svn on the left hand tab side RStudio Global Options dialog with Git/SVN tab highlighted by a red arrow in the left sidebar
  4. Click Create SSH Key... RStudio Git/SVN options pane showing Git and SVN executables, Terminal executable, and SSH RSA Key section with 'Create SSH Key...' button highlighted by a red arrow
  5. I usually don’t create a passphrase. If you do it makes things a bit more complicated to set up, see below.
  6. Click Create
  7. Click Close Dialog box showing successful SSH key creation with SHA256 fingerprint and ASCII art key visualization
  8. Click View public key RStudio Git/SVN options pane showing the generated SSH key path with 'View public key' link highlighted by a red arrow
  9. Press ctrl+c to copy the key to your clipboard.

ONLY DO THIS if you created a passphrase in step 5:

If you created a passphrase for your ssh key in step 6 above, you need to add it to the system.

In a Linux shell/terminal, make sure ssh-agent is running:

$ eval "$(ssh-agent -s)"
# you should get Agent pid 59566, but with a different number

Then add your key.

ssh-add ~/.ssh/id_ed25519

For more info, or instructions on how to do this on Mac or Linux, see section 11.4.3 at Happy Git with R

Add your public key to github

Go to github.com and login to your account

Click on the your profile icon near the upper right hand side and then select settings.

GitHub user profile dropdown menu showing options including Your profile, Your stars, Explore, Integrations, Help, Settings (highlighted with arrow), and Sign out

Click on SSH and GPG keys on the left hand side

GitHub settings page showing Personal settings sidebar with 'SSH and GPG keys' option highlighted by a red arrow

Click on New SSH Key, upper right hand side

GitHub SSH keys page showing a list of existing SSH keys with 'New SSH key' button in green highlighted by a red arrow in the upper right

Enter a name for your key, paste in your public key, then press add SSH key

GitHub 'Add new SSH key' form showing Title field with 'BIS180L 2023', Key type dropdown set to 'Authentication Key', and Key field containing an ssh-ed25519 public key

Test the connection

Open a linux terminal (not R) and type:

ssh -T git@github.com

You may get a warning. Go ahead and type yes. You should then get a message that you have successfully authenticated.

Terminal output showing successful SSH connection test to GitHub with message 'Hi jmaloof! You've successfully authenticated, but GitHub does not provide shell access.'

Set your identity in git

In a linux terminal (not R) type the following, replacing the name and email with your own:

git config --global user.name "Your Name"
git config --global user.email "your.email@ucdavis.edu"

Clone repositories using ssh

In order to use the public key / private key authentication you must clone your repositories using ssh instead of https.

I will provide an example of what this means in the next document “Turning in Assignments”