COMP 206 - Homework 1

Part 1: setting up mimi

Setting up your SoCS account

The first step to access mimi is to set up your School of Computer Science (SoCS) account on our server called mimi. To do so, on McGill wifi (or after connecting to the McGill VPN) visit this page to set up your SoCS account.

You will be assigned a username (which we will refer as your SoCS username, or short username), which is made of the first letter of your first name, followed by the first five letters of your last name, followed sometimes by a number. You will also be assigned a password.

Save the username and password that you received!

Logging in to mimi

Note that until you setup your ssh key (later), you will need to be on the McGill wifi or VPN to connect to mimi.

The first step to connect to mimi is to open a terminal. On Windows, you can open the windows menu and search for cmd (or use winkey+R, then enter cmd). On Mac, you can go to applications and search for Terminal.

We will now use ssh to connect to mimi. ssh is a very versatile program that we use to log into a remote computer. Run the following command:

  • ssh [user]@mimi.cs.mcgill.ca

  • Replacing [user] with your SoCS username. For example, for me this would be ssh mberub20@mimi.cs.mcgill.ca. This tells the ssh command that you want to login to the [user] account on the mimi.cs.mcgill.ca machine.

    You will now be prompted for a password. Enter the password you were given earlier. Note that the password will not appear as you type it! This is by design for security. Copy+paste still works, or you can type it manually.

    You should now be connected to mimi! You should see [user]@teach-node-##:~ at the bottom left of your terminal: the part to the left of the colon ([user]@teach-node-##) indicates that you are connected to account [user] on machine teach-node-## (which is one of the nodes of the mimi server). The path to the right of the colon is your current working directory on this machine: ~ is your user home directory (more on that soon).

    Quick tips

    Once connected, you can change your password:

  • passwd

  • Change to something you will remember. You must use lower/upper case and at least one number/symbol!

    Do not log in to Mimi with your first.last McGill account. It might successfully connect you! But you will be logged in as a generic "campus user", not a SoCS student. Many things that you need for this course will not work correctly as campus user.

    To logout of mimi and go back to your local terminal, you can type logout or exit.

    Setting up a ssh key between your local device and mimi

    You're already used to ordinary passwords, that you type in when you want to log in. But ssh has an alternative mechanism for providing a password. That alternative mechanism is called an ssh key.

    By setting up an ssh key on your local device and adding it to mimi, you will be able to connect to mimi from home without needing the McGill Wifi or VPN.

    The first step is to generate your local key. From your local computer, open a terminal (do not connect to mimi yet) and type:

  • ssh-keygen

  • This will ask to enter a file in which to save the key: you can press enter if you want to use the suggested path in parentheses (I suggest doing this). Note down the path where you saved the key.

    This will also ask you if you want to setup a password for the ssh key: you can press enter directly if you do not want a password (remember that the ssh key itself is going to act as your password, so this is just if you want additional protection in case someone that shouldn't have your private ssh key gets access to it).

    If you go to the location where the key was saved, you should now see two files: one private key (which looks like id_ed25519), and one public key (which looks like id_ed25519.pub).

    As the names suggest, you can distribute the public key however you want, but the private key should be kept private! Using ssh keys to replace passwords works as follows: The public key will first be installed on the machine you want to connect to (in this case, mimi). When you want to connect to that machine at a later time, it will use that public key to craft a challenge that can only be solved by the person who has the private key in their possession. This then proves that you have the authority to log in.

    The first step will thus be to install this public key on mimi! To do this, we'll need to copy the public key from the local computer to mimi. The command to do this is scp, which is already installed on Mac, Windows and Linux out-of-the box. Run the following line on your terminal:

  • scp [path to the public key] [user]@mimi.cs.mcgill.ca:

  • For example, on Windows this could look something like scp C:\Users\mathi\.ssh\id_ed25519.pub mberub20@mimi.cs.mcgill.ca:

    scp takes as input two arguments: the location of the file you want to copy, and where you want to copy it to. Since the location you are copying it to is remote, the address is composed of [user]@mimi.cs.mcgill.ca, which is the machine and user you're sending it to, a colon :, and the path where you want to send it on this machine. Here, since we didn't specify a path after the colon, it will send it to our home directory (~) by default.

    Now, connect to mimi. If you do ls to list the files in the current directory (which is your home (~) directory by default), you should now see your id_ed25519.pub file there. The final step will be to include this file in ~/.ssh/authorized_keys.

    To do this, create a .ssh directory by typing mkdir .ssh from your home directory (the current path after [user]@mimi.cs.mcgill.ca: should be ~). Since this directory starts with a dot, it is a hidden directory: If you type ls, you will still not see it, but if you type ls -a, where the -a flag tells the command to show all files and directories, you should now see .ssh.

    When logging in, ssh looks at the public keys inside the file ~/.ssh/authorized_keys. This file is simply a concatenation of public keys, as such, everytime you want to add a new key you will simply add it to the end of this file.

    If you have never setup a ssh key on mimi yet, this file doesn't exist yet, so we can simply move the public key file to .ssh and rename it authorized_keys. The mv command can do both of this at the same time: - mv id_ed25519.pub .ssh/authorized_keys

    However, if you have already set up a ssh key in the past, the previous command would overwrite it with the new key! If you already have keys (for example if you want to access mimi from two different computers), what you want to do instead is to append the key to this file by doing the following: - cat id_ed25519.pub >> .ssh/authorized_keys

    We will talk more about the >> operator in a couple of weeks.

    That's it! You should now be able to connect to mimi from your local device without having to be on the McGill wifi or VPN! Let us know on Ed if you had any issues!

    Part 2: Setting up your git ssh key

    Assignments this semester will be done on git and autograded. To get these assignments, git needs to confirm your identity: just as in the previous parts, this will be done with ssh key! There are two differences this time:

  • Instead of the private key being placed on your local device and the public key on mimi, this time the private key is on mimi and the public key is on git
  • Instead of generating the private key yourself, IT will email you your private key, and has already added the public key to git.

  • Download the ssh key you received by email to your computer. Assuming your name is Jane Smith, the file you downloaded should be named something like jsmith13-key.

    You will next need to transfer this key into your SoCS account.

    Transfer the file to your mimi home directory using scp. Try to do this by yourself, now that you've already done this once in the previous part!

    Next, log into mimi and do the following:

    Congratulations, you set up your ssh key. You will now be able to obtain and submit the homework via git on mimi.

    Part 3: Creating directories and getting homework instructions

    Check you did it right: ls ~/comp-206/homework/hw1/.git should succeed and show a listing of some strange, internal git files.

    Part 4: Files on mimi

    Next:

    Submission instructions

    To recap, your hw1 directory should contain at this point:

    Then,

    If you need to revise your solution and resubmit it, repeat the three steps in this section: git add ., git commit -m "a message describing the changes", git push.

    You can run the autograder via git push as many times as you like!

    (In practice when doing software development, running git push won't run an autograder, but it will typically run some scripts to run a test suite on your code, compile your code, and deploy your program, i.e. make it accessible to users!)

    Evaluation scheme

    This assignment is graded simply on completion, and the main point of it is to familiarize you with the mechanism by which you'll be doing and submitting your homework throughout the semester.

    Simply pushing with the required files present and of the correct types will earn full marks.