SSH keys
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
-
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 named6.900\psetsin your home directory.- Windows users using WSL: Use your
cdwincommand 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.
- Windows users using WSL: Use your
-
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.
Add a file
- Now,
cdinto that directory, and you should see a few fles. For example, you might see this when youls:
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.
-
Within the
ssh-key-testdirectory, create a blank file in your favorite text editor. -
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.
-
Save the file as
None.mdin thessh-key-testdirectory. -
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
- 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.
- Next do a commit:
git commit -m 'adding my md file'
- 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.