Homework 1

Due: Jan 26, 2022

Computer Setup

There are a lot of things you can do to set up you computer for this course. The document covers what I did. Feel free to copy me. If you do not, you are largely on your own. (If you do copy me, you are only slightly less on your own.) You can set up your personal computer to do almost all of the work required for this course. (You will still need to submit electronically on the CS Lab machines.)

Be aware that all programs MUST compile and run the course server. So even if you do everything on your own computer (and doing so would be really hard; possible, yes, realistically doable, no), before turning in assignments you will probably want to test on the course UNIX server.

Please note: this is a really long configuration process, with many places to go wrong. I have checked this on both Windows and Macs, but it is possible that I missed some steps. I encourage you to follow these directions slowly. Do you best to understand, not just type. (I know that there is a lot here that you may not understand.)

TYPOGRAPHY: I attempt below to always put commands to be typed into a terminal on lines by themselves and in the teletype font.

Step 1: Install Software

We will be using one (1) package during the course that is useful to install on your personal computer:
  1. Visual Studio Code -- an IDE. I use VSC for all editing and running. Download at https://code.visualstudio.com/download. If you want to use a different IDE, that is OK.

Step 2: Set up VSC

(These direction work on my Mac. They are less tested on Windows. If you find issues, let me know.)

Beyond the basic VSC installation, I use -- and recommend using -- the following extensions:
Remote Development v 0.21.0 by Microsoft
This is an extension pack (it installs several extensions). It allows you to use VSC on your own device to directly edit files on remote machines (specifically, I use this to edit files on the server used for this course).
HTML Preview v0.2.5 by Thomas Townsend
This just makes it easier to see html you might be editing. In all probability you will write some fairly simple HTML for this course.

Step 3: Set up public/private keys

This makes it very easy to transmit materials between your computer and the lab computers -- and also to log into the lab computers. This is pretty much required to use the remote development extension of VSC. You will be very, very sad if you do not get this set up. (If you already have a public/private key pair set up -- for instance becauase you took either 245 or 246 with me -- then do not create another pair.)
  1. Create a Public/Private key
    Open a terminal window (You will use terminals a lot this semester.)
    On a mac: Start the Terminal program in Applications/Utilities
    On Windows: Open a windows powershell (type powershell in the search box in lower left then hit enter)
  2. Enter the following command to start the key generation process
                ssh-keygen -t rsa
    Press the ENTER key to accept the default location. The ssh-keygen utility will then prompt you for a passphrase. Press enter to give no passphrase. The point of creating the key is so that you do not need to enter a pass phrase (or password) all the time
  3. cd to the location you were told was the default location. Usually this will work
    cd .ssh
    In this directory you should see two files: id_rsa and id_rsa.pub. These are your private and public keys
  4. Execute the following command
    scp id_rsa.pub YOUR_NAME@goldengate.cs.brynmawr.edu:mpub
  5. ssh into that machine
    ssh YOUR_NAME@goldengate.cs.brynmawr.edu
  6. on goldengate
    mkdir .ssh  
    cd .ssh
    if this directory contains the file authorized_keys then on goldengate
     cat ~/mpub >> authorized_keys
    cp ~/mpub authorized_keys
  7. exit goldengate
  8. log back into goldengate as in step 5. If everything worked correctly you should not have to enter a password. This is what you want! If you are still asked for a password, you did something wrong. Find me for help (or try again, or ask a classmate).

Set up an ssh config file

  1. Within the .ssh directory on your local machine create a file named config. You can use VSC to create this file. Alternately on Windows use notepad and on a mac use textedit. If you use notepad or textedit, they will want to put a ".txt" extension on the file. You will need to get rid of that, as below.

    Into config file put the following:
            Host golden
                 HostName goldengate.cs.brynmawr.edu
                 User YOUR_UNIX_NAME
            Host db
                 User YOUR_UNIX_NAME
                 LocalForward 5432 localhost:5432
  2. In a terminal window
    cd ~/.ssh
  3. Check the file name you just created
    if the file is named just "config" that is what you want. If it is named "config.txt" On a Mac:
    mv config.txt config
    On windows (I think):
    rename config.txt config
  4. test this configuration. In a terminal/powershell
                ssh golden
    The configuration is important. The remote ssh extension package you installed into VSC requires it. If the test above does not work, find me.

    Do not go further with these instructions until you have a working keypair and config file.

    (There is a lot more you can do with configuration files. Feel free to explore.) The first config gets you to goldengate; one of the department's servers. For file copying and general low-level stuff you can use that. The second connects you to the server you will principally use for 383. Goldengate and this machien use a shared file system; all of your files will be visile from both machines.

Make a directory where all of your work will live on CS servers

open a terminal/powershell and connect to goldengate using ssh (you can use the terminal from previous steps if it is still open) Create a folder into which all of your 383 work will be put. Then create a folder inside of that into which one assignment (or lab) or whatever will be put. For example:
            mkdir CS383
            cd CS383
            mkdir lab2
            cd lab2
            touch test.txt
Leave this terminal open and connected. YOU will reuse it is a couple of minutes

Within VSC use RemoteSSH to connect to the directory you just made

  1. Open the "command palette". (View menu / Command Palette" (the F1 key usually works also)
  2. Enter "remote-ssh: connect to host" You actually just need to enter enough of this to get that option to show, then tap on the item
  3. You should get a list of hosts to connect to. These should be the ones you set up in the config file. Tap on db.
  4. This will likely open a new VSC window. If all is well in the bottom left of this window you will see a green box with "SSH: db" in it. Your window should look someting like this
  5. Tap on "Open ..." underneath "Start" new the top of this window. In the popup select the CS383 diretory you just made.
  6. Open the file test.txt, enter something into it, then save

Final steps

Back in the terminal you left open
    cat test.txt
You should see the changes you made using VSC

Unix checks

The final setup step is to check that you can access the software installed on the UNIX server we will be using for this class. Do the following:
  1. Open a terminal to the database server. ssh db should work
  2. At a UNIX prompt enter the command psql to enter the PostgreSQL command prompt window.
  3. Enter the following commands into the psql command prompt A simple SQL command to test that SQL commands work
    \lList the available databases
    \c rocketConnect to the rocket database
    \dtList the tables in the connected database
    select count(*) from launch;
    exit;Exit psql
  4. At a unix prompt enter mongosh to enter the mongo command prompt
  5. Enter the following commands into the psql command prompt A simple command to test that mongo works
    show dbsList the available databases
    use rocketConnect to the rocket database
    db.getCollectionNames()List the collections in the connected database
    exitExit mongo

What to turn in

Having done all of the above, write a 1-2 page report. The report should have two parts. The first part is simply a copy of your public key and the number returned by the search commands in psql and mongo. The second, part is a description of how ssh works (one page on this is probably sufficient). In particular, focus on how ssh uses the stuff you did above in the assignment. Your report should cover the following topics
  1. Exactly when and how at the public and private keys used?
  2. Are the public and private keys always used and if not, why not?
  3. How is the the config file used by SSH?
  4. What does LocalForward 5432 localhost:5432 do?
  5. At least one topic of your own choice (about ssh)

Citations:most (all) of the material you will need to write this report is available of the web. Use it. Cite it. If you directly quote, then indicate hat you are directly quoting.

You may submit this report either as a plain text file or a PDF.

How to submit

Get your report onto a unix server. Once there, go to the 383 directory you created earlier. Make a new directory -- for instance HW1. Put your report into the HW1 directory. Change your own directory to your 383 directory. Execute the following command
    /home/gtowell/bin/submit -c 383 -d hw1 -p 1 
There may be other versions of this program on the servers. Be sure to use mine. The arguements here have the following meanings: You may submit as many times as you like. Successful use of submit is a part of the grade for this assignment. So try this step early. If you cannot get it to work ask me or a classmate.