Homework 1
Due: Jan 31, prior to 11:59:59 PM
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. In this assignment you will replicate my setup. After this assignment you can continue to use this setup (suggested), or do something totally different.
Be aware that all programs MUST run on the lab computer dedicated to this course. There is only 1.
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:Commands to be typed into a terminal appear on lines by themselves and in
the teletype font.
Step 1: Install Software
We will be using one (1) package during the course that you should install on your personal computer:
- Visual Studio Code -- an IDE (Integrated Development Environment). I use VSC for all editing and running. Download at https://code.visualstudio.com/download. If you want to use a different IDE (after this assignment), that is OK. (Again, you will be on your own.)
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 extension:
- Remote - SSH v 0.107.1 by Microsoft
- (Required for this assignment.) This allows you to use VSC on your own device to directly edit files on remote machines. (I use this package to write all of the programs 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 required for easy use of the remote-ssh extension of VSC. (Remote-ssh will actually prompt you for a password if you do not have a key pair installed.) If you already have a public/private key pair set up then do not create another pair.
- Create a Public/Private key
Open a terminal window (You will use terminals a lot this semester.)
On a mac: Start the Terminal program. It is in Applications/Utilities
On Windows: Open a windows powershell (type powershell in the search box in lower left then hit enter)
(Mac and Windows) You can also open a terminal from within VSC (Terminal Menu / New Terminal)
-
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
-
cd to the location you were told was the default location. Usually this will work
cd .ssh
if not then maybe this
cd ~/.ssh
In the .ssh directory you should see two files: id_rsa and id_rsa.pub. These are your private and public keys, respectively.
-
Execute the following command
scp id_rsa.pub YOUR_NAME@goldengate.cs.brynmawr.edu:mypublickey
You will need to enter your UNIX password to complete this command. This copies your public key from your laptop to the Unix machines in the lab.
-
ssh into goldengate
ssh YOUR_NAME@goldengate.cs.brynmawr.edu
Again, you will need to enter your UNIX password
- On goldengate do the following
ls -a
to list all of the files in your home directory. In the listing look for a directory named ".ssh". If you do not have a directory so named, make one
mkdir .ssh
Now get into that directory
cd .ssh
if this directory contains the file authorized_keys then on goldengate
cat ~/mypublickey >> authorized_keys
This will append your public key to the file authorized_keys.
Else
cp ~/mypublickey authorized_keys
-
Finally, exit goldengate
exit
-
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
-
Within the .ssh directory on your local machine create a file named config. You can use VSC to create this
file (recommended). The easiest way to do this is
- install the remote-ssh VSC extension (as described above)
- open the command palette (usually by hitting the F1 key)
- enter/select "remote-ssh: open ssh configuration file". In the choices that come up, select one like that has your home directory followed by ".ssh/config"
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 the extension, as below.
Into config file put the following:
Host *
StrictHostKeyChecking no
ConnectTimeout 5
Host goldengate
HostName goldengate.cs.brynmawr.edu
User YOUR_UNIX_NAME
Host db
HostName 165.106.10.133
User YOUR_UNIX_NAME
LocalForward 5432 localhost:5432
Most of the work you will do this semester will be on the machine you configured as 'db'. It is has all of the packages you will be using (postgres, mongo, node, ...)
In the above you will need to replace YOUR_UNIX_NAME with your unix login name.
- In a terminal window
cd ~/.ssh
- Check the file name you just created
ls
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
-
test this configuration. In a terminal/powershell
ssh db
You should be logged into the machine without needing to enter your password. Confirm you are logged into the correct machine by executing the following Unix commands
which psql
#response should be "/bin/psql"
psql --version
#response should be "psql (PostgreSQL) 16.1 (Ubuntu 16.1-1.pgdg20.04+1)"
which mongod
#response should be "/bin/mongod"
node --version
#response should be "v21.5.0"
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.
- Test the configuration inside VSC.
- open the command palette (usually by hitting the F1 key)
- enter/select "remote-ssh: connect to host".
- This should give you 2 choices (or more if you set up a config file previously. Select "db"
- Open a terminal and repeat the above tests.
(There is a lot more you can do with ssh 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. As above, almost all of the work done this semester will be on the machine db.
Make a directory where all of your work will live on CS servers
open a terminal/powershell and connect to goldengate (or a lab machine) using ssh (you can use the terminal from previous steps if it is still
open).
Create a folder into which all of your 245 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 HW1
cd HW1
touch test.txt
Database access 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:
- Open a terminal to the database server. ssh db should work
- At a UNIX prompt enter the command psql to enter the PostgreSQL command prompt window.
- Enter the following commands into the psql command prompt
Command | Explanation |
\l | List the available databases |
\c rocket | Connect to the rocket database |
\dt | List the tables in the connected database |
select count(*) from launch; | A simple SQL command to test that SQL commands work
exit; | Exit psql |
- At a unix prompt enter mongosh to enter the mongo command prompt
- Enter the following commands into the psql command prompt
Command | Explanation |
show dbs | List the available databases |
use rocket | Connect to the rocket database |
db.getCollectionNames() | List the collections in the connected database |
db.Launches.find().count() | A simple command to test that mongo works
exit | Exit 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 should contain:
- copy of your public key
- The number returned by the SQL "select" command
- The number returned by the mongo "count" command
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
- Exactly when and how at the public and private keys used? What I am looking for here is a detailed description of the SSH protocol that shows all of the steps involved in establishing a secure connection and where / how your public and private keys are used in that process.
- Are the public and private keys always used and if not, why not?
- How is the the config file used by SSH?
- What does LocalForward 5432 localhost:5432 do?
- 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 that you are directly quoting.
You may submit this report either as a plain text file or a PDF. Do not sumbit this report in any other format.
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 (you might have made this in following the instructions above). 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 the submit program on the servers. Be sure to use mine.
The arguments here have the following meanings:
- -c: the course number
- -d: the directory that contains the material to be submitted
- -p: the assignment (project) number
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 this submission procedure to work; ask me or a classmate.