Getting Started

Written by Chris Gregg, Julie Zelenski and others, with modifications by Nick Troccoli and Lisa Yan

This guide walks you through all the steps to start working on assignments in CS111. You will complete all your programs for CS111 by SSHing into the myth cluster, which is a set of computers in Gates B08 running Linux (Ubuntu 14) and have various open source tools installed (gcc, gdb, etc.) that we will use.

SSHing Into Myth

The first step is to set up your own computer to log in to myth via SSH. The instructions for doing this are the same as from the CS107 getting started guides - see this guide for info on logging in:

Open CS107 Getting Started Guide

Choosing a Text Editor

For CS111, you are welcome to choose any text editor you'd like. You can use a terminal editor while SSHed into myth such as Emacs or Vim, which means you are editing the files directly on myth to minimize version mishaps. Alternatively, you can use a local graphical editor that you install on your own computer that can edit remote files, such as Sublime Text or Visual Studio Code - however, there is a slightly higher risk of version mishaps as you are editing files locally and transferring them back and forth on opening/saving. The course staff is also not always able to help troubleshoot local editor issues since we may not be familar with the installation/setup process, though we will do our best. Here are notes for various editors you might choose:

Emacs (Terminal Editor)

Check out the CS107 guide to Emacs here. Make sure to download the CS107 Emacs configuration file, by executing the following command immediately after logging into myth:

wget https://web.stanford.edu/class/cs107/resources/sample_emacs -O ~/.emacs

Vim (Terminal Editor)

Check out the CS107 guide to Vim here. Make sure to download the CS107 Vim configuration file, by executing the following command immediately after logging into myth:

wget https://web.stanford.edu/class/cs107/resources/sample_vimrc -O ~/.vimrc

Visual Studio Code / VSCode (Local Editor)

Visual Studio Code is a local graphical editor you can download to your computer (supports Windows/Mac/Linux). It supports editing remote files by downloading them to your local machine and re-uploading them when saved. You still compile, run and test your program using the terminal, but you can edit your files using a graphical editor.

This tutorial is based on a great previous tutorial video by Jonathan Kula - you can view it here, though note that some steps are slightly different in the instructions below than in the video.

  • Install VSCode: download it from the Visual Studio Code website (Mac users may need to drag the app from their Downloads folder into the Applications folder)
  • Download CS111 VSCode configuration profile: Click here to download
  • Install CS111 VSCode configuration profile (this will overwrite any existing VSCode settings): open VSCode, and open the command palette (which is a keyboard-based way to perform actions, typing what you'd like to do) by doing Command-Shift-p (Mac) or Control-Shift-p (Windows/Linux) and enter "Profile". Select the option "Profiles: Import", confirm you want to proceed, select "Import from profile file" and navigate to where you saved the CS111 VSCode configuration file to select it.
    • If you are already a VSCode user and don't want to overwrite any existing settings, instead of importing this profile, click the extensions tab and install the extensions "Remote - SSH" and "C/C++ Themes". Also click the gear icon in the bottom left corner of the VSCode window, select "Settings", search for "flock", and make sure "Remote.SSH: Use Flock" is unchecked.
  • (WINDOWS ONLY) Install SSH: follow these instructions (under "How to install OpenSSH using Settings") to ensure you have ssh installed if you haven't already installed it.
  • Add myth machine login: open the command palette and enter "SSH Configuration", and select the option "Remote-SSH: Open SSH Configuration File". Select the filename with your personal computer user account in it (e.g. something like /Users/nicktroccoli/.ssh/config). Add the following lines at the end of the file and save it - replace XX with a random number between 51 and 66 (click here to generate one) and replace YOUR_SUNET_ID with your sunet ID.

Mac/Linux:

Host mythXX.stanford.edu
  User YOUR_SUNET_ID
  ServerAliveInterval 60
  ControlMaster auto
  ControlPath ~/.ssh/%r@%h:%p
  ControlPersist yes

Windows:

Host mythXX.stanford.edu
  User YOUR_SUNET_ID
  ServerAliveInterval 60
  • Log in to myth: open the command palette and enter "Connect to host", and select the option "Remote-SSH: Connect to Host". Select the myth machine name that appears (which should match the one you just entered in your config), and a new window should open (you can close the old one). It may prompt you to enter your myth (same as Stanford/Axess/etc.) password at the top of the window. After a little bit (it may take 30sec or so the first time), it should connect and you should see a green area in the bottom-left corner of the window change from "Opening Remote..." to "SSH: mythXX.stanford.edu".

  • Open terminal: in the top VSCode toolbar, click "Terminal" -> "New Terminal" and it should open a terminal window connected to the myth machine. You can use this to run, compile, debug, etc. just like you can do in a separate terminal program.
  • (Recommended) Create a myth folder for CS111: in the terminal, make a new folder (mkdir) for your CS111 work this quarter - that way it's all in one place
  • Open files: click the "files" icon at the top of the left toolbar and click the "Open folder" button. A menu should pop up listing the contents of your myth home directory; select the folder you would like to open in VSCode (e.g. the one you previously created for CS111) and press "OK". (If it asks you if you want to trust the authors of the folder, select "Yes"). Now it should appear in the left sidebar and you can click any files you add there to open and edit them. When you save them, they will be automaticallly synced back to the myth machines.

From now on, when you launch VSCode, you can re-connect by running "Remote-SSH: Connect to Host" from the command palette, and selecting myth.

Troubleshooting / FAQ

  • if VSCode doesn't accept your password when logging into myth, try logging in once via a standalone terminal program first (like Terminal on Mac); sometimes myth will require two-step authentication the first time you log in from a new location. From that point onwards, you can then log in via VSCode.
  • if you get a "permission denied" error in the terminal when you are SSHing into myth via VS Code and can't access any files, try running kinit && aklog in the terminal to refresh your credentials - it should prompt you for your password again and you should be good to go.
  • if you get an error "Could not fetch remote environment" and "Error: WebSocket close with status code 106", you'll need to go back to an earlier version of the "Remote - SSH" package (a later one introduced an issue). Click the extensions tab and select the "Remote - SSH" extension, and click the downward error next to "Uninstall" and choose "Install Another Version". Then choose version 0.74. Reload it and you should be good to go.
  • (courtesy of CS106L) Sometimes, when you quite VS Code and reopen, the SSH password prompt gets stuck on a loop and won't let you log in. If this is happening to you, press command + shift + P on Mac or ctl + shift + P on Windows and type "kill", and select the option "Remote-SSH: Kill VS Code Server on Host". Now enter your password again and you should be good to go.
  • If you get an error "Could not establish connection, cannot find module minimist", Log into myth via a separate terminal program and as soon as you log in (from your home directory), execute rm -rf .vscode-server. Be careful with this command, however, as it force deletes without confirming first; so make sure you execute this right after you log into myth. Then restart VS Code and try again.

Sublime Text (Local Editor)

Sublime Text is another local graphical editor you can download to your computer. It supports editing remote files by downloading them to your local machine and re-uploading them when saved. You still compile, run and test your program using the terminal, but you can edit your files using a graphical editor. You will need to download Sublime Text as well as the "SFTP for Sublime Text" package, which adds the capability to edit remote files.

Download Sublime Text Download SFTP for Sublime Text

Once you set up SFTP for Sublime Text, add a new server by selecting the "Edit Server" command, and in the server configuration change "host" to "myth.stanford.edu", "user" to your SUNET ID (e.g. "troccoli") and "remote path" to "/afs/ir/users/t/r/troccoli", where the "t" is replaced with the first letter of your SUNET ID, the "r" is replaced with the second letter of your SUNET ID, and the "troccoli" is replaced with your full SUNET ID.

Working on Assignments

CS111 uses the make, gdb, and valgrind to compile and debug, and the custom sanitycheck, submit tools to test and submit (these are the same as used in CS107). Check out this CS107 guide for more information on the workflow for compiling/testing/submitting assignments, which is the same in CS111:

Open CS107 Guide to Working on Assignments

The CS107 Debugging Guide has tips for approaching debugging and using GDB and Valgrind:

Open CS107 Debugging Guide