SSH keys

You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

In EX01 (and beyond) you'll need to work with git repos on github.mit.edu. To do that effectively, you'll want to use SSH keys, and sometimes students have issues getting those keys to work.

We want to identify and sort out any issues before the last minute, and so this simple exercise is intended to ensure that your SSH keys work.

Setting up github.mit.edu with SSH

First, make sure you have followed the instructions on our Software Install. If you've done that succesfully, the rest of this exercise will be straightforward.

Clone the exercise

  1. Open a terminal. Navigate to the directory (using cd) where you would like to store this exercise's repo. For example, that might be a directory named 6.900\psets in your home directory.

    • Windows users using WSL: Use your cdwin command that you created when setting up Git to navigate to your Windows folders, since eventually you'll be cloning repos for KiCad, which only has access to your Windows folders.
  2. Clone the repo. In your terminal, run the following command:

git clone git@github.mit.edu:6-900-S26/ssh-key-test.git

You should see something like this (the number of objects may differ):

voldman@joelslaptop2023:.../Teaching/6.900-S26/code$ git clone git@github.mit.edu:6-900-S26/ssh-key-test.git
Cloning into 'ssh-key-test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
voldman@joelslaptop2023:.../Teaching/6.900-S26/code$

There should now be a subdirectory named ssh-key-test.

If you have issues, reach out on Piazza.

By far the most common issue we see is that the ssh key registered on github.mit.edu differs fom the key they are using locally. Especially in windows, if you generate an ssh key in the Windows Terminal, it won't automatically make its way to the wsl terminal. Or if you have a key from an old laptop, it might not be present on your new laptop.

Add a file

  1. Now, cd into that directory, and you should see a few fles. For example, you might see this when you ls:
voldman@joelslaptop2023:.../Teaching/6.900-S26/code$ cd ssh-key-test/
voldman@joelslaptop2023:.../6.900-S26/code/ssh-key-test$ ls
README.md  jodalyst.md

To test that you can push to the repo, we're going to make a trivial change of adding a one-line file.

  1. Within the ssh-key-test directory, create a blank file in your favorite text editor.

  2. Add one line of text to that file. It can be anything you want, like "6.900 is cool", or "I wish I was a GenXer", or "Eleven is alive", etc.

  3. Save the file as None.md in the ssh-key-test directory.

  4. Now when you list the directory contents, you should see your file there:

voldman@joelslaptop2023:.../6.900-S26/code/ssh-key-test$ ls
README.md  jodalyst.md  voldman.md

Push to the remote repo

  1. Next, you need to stage your newfile. In your terminal, type:
git add .

This will add all the files in the folder -- basically the file you just created -- to your local copy of the repository.

  1. Next do a commit:
git commit -m 'adding my md file'
  1. Finally, push to the repo:
git push origin main

If it worked, you'll get something like this:

voldman@joelslaptop2023:.../6.900-S26/code/ssh-key-test$ git push origin main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 20 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 385 bytes | 5.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To github.mit.edu:6-900-S26/ssh-key-test.git
   6f4363f..b0c6ab3  main -> main
voldman@joelslaptop2023:.../6.900-S26/code/ssh-key-test$

However, it's entirely possible that when you do this, you'll get an error that looks something like:

! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.mit.edu/6-900-S26/ssh-key-test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

If that occurs, it's almost certainly because another student pushed their file to the remote repo in the meantime, so your repo and the remote repo are out of sync.

No big deal. Just pull (the changes from the remote to your local copy of the repo), and then push again:

git pull
git push origin main

If all works well, your files should now be up on github.mit.edu. You can check on this by looking at the repo on your browser.

Q: I can't get ssh keys to work. Can I just have my friend add a file on my behalf? A: No. We will be checking commit logs, not the files, to ascertain completion of this exercise.

Q: I don't want to use ssh keys. I'd rather just use github.mit.edu on my browser to interact with repos. A: It's going to be terribly annoying to work that way throughout the semester. We know, because someone has tried it in the past. Use ssh keys and the command line.