Lab 1 and 2 --- 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 on the Unix servers. So even if you do everything on your own computer, before turning in assignments you will probably want to test on Unix.

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 will 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 3 packages during the course:
  1. Go: a programming language. You can download go at https://golang.org Be sure to get at least version 1.16.x
  2. Kotlin: a programming language. I assume you will be using Kotlin in command line mode. For installation directions https://hub.packtpub.com/getting-started-with-kotlin-programming/ (This is sufficiently annoying that I amost gave up on Kotlin.) Ignore all of the stuff about installing the JetBrains IDE. You should have at least version 1.4.21 of Kotlin
  3. Visual Studio Code -- an IDE. I use VSC for all editing and running. Download at https://code.visualstudio.com/download.

Step 2: Set up VSC

(These direction work on my Mac. I have not exactly tried them on Windows. If you find issues, let me know.)

Beyond the basic VSC installation, I use -- and recommend using -- the following extensions:
Better comments
v2.1.0 It helps a little
Code Runner
v0.11.5 This makes it easy to run Kotlin and Go from within VSC. (Usually. Sometimes coderunner gets confused with Kotlin.)
Go
v0.26.0 Go language support
Kotlin Language
v1.7.1 Kotlin language support
Print Code
v3.0.0 If you never want a paper copy, do not bother. Otherwise it is great.
SFTP
v1.12.9 Automatic sync between your computer and the linux servers. Requires a lot of setup (but once set up it is great if only because it creates automatic backups of all your work.)
Tabnine
v3.4.15 Sometime I think this is great. Sometimes I feel like in gets in my way. (It tries to anticipate your programming and save you typing.)

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.
  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 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
    else
    cp ~/mpub authorized_keys
  7. exit goldengate
    exit
  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.

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
                 Port 22
                 
            Host g186
                 HostName 165.106.10.186
                 User YOUR_UNIX_NAME
                 Port 22
                 ProxyCommand ssh -q -W %h:%p golden
            
  2. In a terminal window
    cd ~/.ssh
  3. 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
  4. test this configuration. In a terminal/powershell
                ssh golden
            
    The configuration saves you a little extra typing. (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 use that. The second configuration goes through goldengate to connent to a machine in the CS labs. Anything that takes more than 10 CPU seconds should be done on a lab machine.

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 step 5 if it is still open) Create a folder into which all of your 245 work will be put. The create a folder inside of that into which one assignment (or lab) or whatever will be put. For example:
            mkdir 245
            cd 245
            mkdir test1
        

Back in a terminal on your own computer, you should be able to do the following assuming you named the hello world file hw.go:

        scp hw.go golden:245/test1/
    
which will copy the file hw.go to the directory 245/test1 using the name hw.go on the lab computers.

Instead of copying one file at a time, you could also do

    scp * golden:245/test1/
which will copy all of the files in the current directory on your computer up to the lab computers. (I use this command a lot)

To check that the file is actually on the lab computers, back on the terminal you have open to the lab computers
        UNIX> hostname 
                  response: goldengate
        UNIX> pwd
                  response: /home/YOUR_LOGIN/245
        UNIX> cd test1 
                  response: 
        UNIX> ls
                  response: hw.go
    
The first line just confirms that you are, in fact, in the correct terminal. The second confirms that you are in the righ place. The third moves you to the place where you copied files. Finally the fourth shows you all of the files in that location.