Remote SSH for Programming C++

Running VS Code on your own computer (Windows, MacOS or Linux) is a great way to have a responsive and productive development environment. This guide will walk you through installing VS Code on your computer and then using the CS server ("CSIL") to compile, run, and debug your program. Your files will be stored on SFU's server (in your SFU home folder), which is backed-up and accessible on any compute at SFU.

Steps to Install Software (do once)

  1. Install SFU's VPN client on your computer:
    • Install the Fortinet VPN program by following these SFU directions.
    • VPN stands for a Virtual Private Network: it is a secure way of connecting your computer to SFU's network.
  2. Install VS Code on your computer:
  3. Install "Remote SSH" extension in your VS Code:
    • Launch VS Code on your computer.
    • On the very left, in the Activity Bar, select Extension
    • Search for "Remote - SSH", and click install.
    • This extension allows your VS Code to connect to a CSIL server. You can then use the server to build, run, and debug your program without having to install a compiler.
    • This extension requires your computer to already have an SSH installed, which is very likely on most modern systems (Mac/Windows/Linux). For details, see VS Code docs.
    • In your VS Code, you should now see the Remote Explorer button on the very-left activity bar.

Steps to Set Up a Connection (do once)

  1. Launch SFU's VPN:
    • Run the FortiClient VPN to securely connect your computer to SFU's network.
    • This seems to be needed even if you are connected to SFU's secure wifi.
  2. Connect your VS Code to remote CSIL computer:
    • Launch VS Code on your computer.
    • Select the "><" green button in the very bottom left of VS Code ("Open a Remote Window")
    • Notice the prompt to "Select an option to open a Remote Window" (at the top of your screen):
      Choose "Connect to Host..." > "+ Add New SSH Host"
    • Type in:
      ssh -p24 your_sfu_computing_id@csil-cpu##.csil.sfu.ca
      • your_sfu_computing_id is your SFU Computing ID, such as bfraser or abc52
      • csil-cpu## is one of the CSIL Linux CPU servers. We don't all want to connect to the same one, so randomly pick one you like! In the future, you can connect to a different one and still have all your files there.
      • For example, I might use the following command:
        ssh -p24 bfraser@csil-cpu11.csil.sfu.ca
        (Yes, I know there is no cpu11 computer; so pick one from 01 to 10!)
      • Press ENTER to accept
    • VS Code will ask "Select SSH configuration file to update"; pick the first one.
    • If prompted, select to "Connect" to the server.
    • A new VS Code window will appear;
      • If prompted to "Select the platform of the remote host...", select Linux.
      • If prompted to confirm the fingerprint, accept it with Continue.
      • It may take a minute for the connection steps to complete.
    • The new VS Code window may prompt you for your SFU password to authenticate you.
    • You will see in the very bottom left on the "><" button that it is connected:
      ">< SSH: csil-cpu##.csil.sfu.ca"
  3. Install C/C++ extensions:
    • VS Code needs extensions to be installed for remote connections. VS Code may prompt to install extensions for your connection. These extensions allow VS Code features such as Intellisense and build/run/debug.
    • On the left activity bar, select Extensions
    • Search for "C/C++ Extension Pack"
    • Select "Install in SSH:..."
  4. Create cmpt130 folder on the CSIL server for your course work:
    • We will create a folder on the SFU server to store your code. All your code will be securely stored on the SFU server, so you can connect from any computer to access your files.
    • In your VS Code, while connected via the Remote SSH to CSIL, open a terminal by going to the menu at the top (you may need to click the "..."):
      Terminal > New Terminal
    • Change to the folder that is your SFU provided space to save your files:
      cd ~/sfuhome
      • This folder will be available to you on all SFU computers (CSIL labs, CSIL via SSH or VDI, and all SFU computer labs).
      • Other locations under the "~" folder (which is called the "home" folder) are on the CSIL server and would be available only when connected to any CSIL machine.
      • Using ~/sfuhome makes it available on all SFU lab computers (not just CS labs).
    • Make sure that the SFU home folder has correctly "mounted" (become available to use):
      ls
      If you see @_This_IS_NOT_your_real_sfuhome_README.txt, then see troubleshooting below.
    • Create a folder for CMPT 130:
      mkdir cmpt130
      Note: No spaces, suggest keeping all the characters lower-case (but you can pick).
  5. Open the cmpt130 folder:
    • In VS Code, from the menu at the top, select: File > Open Folder...
    • In the drop-down menu at the top, select sfuhome (have to scroll down to bottom), and then select cmpt130.
    • Click OK.
    • If asked "Do you trust the authors of the files in this folder?", select "Yes, I trust the authors".

You are now ready to program! Follow the steps below to get a program running (skipping the first few steps because you have just done them).

Steps to Write Your Program (do each time)

Since you now have everything installed and setup, next time you can do the following:

  1. Connect to SFU via the VPN (if off campus).
    • Run the FortiClient VPN to securely connect your computer to SFU's network.
  2. Connect your VS Code to a remote CSIL computer:
    • Click the "><" button (very bottom left)
    • Select "Connect to Host..."
    • Select "csil-cpu##.csil.sfu.ca" (OK to have numerous ones to choose from!)
  3. Open your cmpt130 folder:
    • File > Open Folder...
    • Select sfuhome and then cmpt130, then OK.
  4. Create folder for your work (like the lab or assignment):
    • In the Explorer pane on the left, select the "Create Folder" button at the top.
    • Name the folder based on what you are working on, such as lab1, or lecture_week_2
    • Creating folders for your work helps organize all your files; don't put spaces in the filename
  5. Open/Create file:
    • Right-click on your lab1 folder (or whatever name you gave it) and select "New File"
    • Name the file as needed, such as main.cpp.
    • Click on the file you created to open it.
  6. Code, Build, Debug:
    • Write your C++ code in the file
    • Run your C++ code by either:
      • Above your code, click the Debug C/C++ File button
        (Or, click the drop-down beside it and select to Run C/C++ File)
        If prompted to "Select a debug configuration", choose "C/C++: g++ build and debug active file...". If given multiple options, pick the first one listing "g++" (not "gcc"!)
      • Via the menu at the top select: Run > Start Debugging (or Run Without Debugger)
      • Press F5 (or whatever hotkey File > Start Debugging lists)
  7. Disconnect VS Code from CSIL:
    • Once you are finished for the day, disconnect from the CSIL server (it's a shared resource!).
    • Either:
      • Click "><" in bottom left and select "Close Remote Connection", or
      • via the menu: File > Close Remote Connection

Submitting Code from Remote SSH

When developing using the Remote SSH connection to SFU, your files are saved on the server. Since we put your cmpt130 folder under your sfuhome folder, it means all your files are stored on SFU's central file server. This server is backed up and secure!

To submit your code you can do any of the following:

  • While VS Code is connected via the Remote SSH connection to SFU:
    1. Open the file of interest in VS Code.
    2. Save a copy of the file locally to your computer:
      File > Save As...
      Note: This is now a copy! Ensure you don't edit this copy otherwise you'll have two versions which never goes well!
    3. Launch your web browser and submit the file you just saved.
    4. Delete the local copy of the file so you don't have multiple versions floating around!
  • Or, connect to the CSIL computers using a graphical interface (such as VDI), and use a web browser through it to submit your files by browsing to ~/sfuhome/cmpt130. This keeps all the files in one place (on the server) and not on your computer.
  • Or, use any SFU lab computer to access your files from ~/sfuhome/cmpt130.

Troubleshooting

  • If you cannot find the "><" then "Open a Remote Window" button it likely means that you either need to install the Remote SSH extension in VS Code, or install the OpenSSH client may not be install on your computer.
    • Under Windows, you can install the OpenSSH client by:
      Start > Settings; search "Optional features"; search for OpenSSH Client and add if needed.
  • If VS Code seems to hang while trying to connect to the CSIL server via SSH:
    • Ensure you have a stable network connection, and that you are running the SFU VPN.
    • Try letting it work for about a minute.
    • Close the window and try to connect again.
    • Try a couple different CSIL servers (choose a different number); any of them should work.
    • If the problem persists contact your instructor.
  • If your ~/sfuhome folder does not have your files and only has @_This_IS_NOT_your_real_sfuhome_README.txt:
    • If you see this file then it means that the real SFU home folder is not available! Don't use this folder until you resolve the issue, otherwise your files will not be saved.
    • On the SFU network, your home folder exsits on a file server. The CSIL system "mounts" that folder into ~/sfuhome. For some reason, the CSIL server was not able to mount your folder correctly.
    • Try:
      • Close your VS Code, open it again and reconnect.
      • Connect to a different CSIL server (choose a different server number: 01 to 10).
      • Run klist. If it says "No credentials cache found..." then run kinit (enter your password when prompted), log out and log back in. ~/sfuhome/ should now be fixed.
      • Read the file for some things to try:
        cat @_This_IS_NOT_your_real_sfuhome_README.txt
      • Reach out to CS Helpdesk. Let them know your SFU Computing ID, the server you are trying to access, and that you are seeing the @_This_IS_NOT_your_real_sfuhome_README.txt file.

(Inspired by guide created from Dr. Victor Cheung's initial guide).