Connecting a local VS Code installation to OSC
1 Introduction
During the course, you’ve been connecting to OSC through the OnDemand web portal. However, there is another more basic and universal method to connect to remote computers: SSH, which is short for Secure Shell. An optional self-study page on SSH shows you how to directly use the ssh command in a terminal on your own computer to “move” to OSC within that terminal.
This page shows you how to connect a VS Code installation on your computer to OSC using so-called “SSH tunneling”. This connects VS Code to OSC in such a way that not just the terminal but the entire program operates on OSC.
This requires some setup, and because it relies on a local installation of VS Code, may lead to more heterogeneity in the environment: therefore, we didn’t make this the default way to connect to OSC in this course.
This has several advantages over using VS Code Server through OnDemand, such as:
- You won’t have to fill out an OnDemand form every time.
- You can easily have multiple VS Code windows open at the same time.
- VS Code “proper” has some functionality not available in the Server version, and moreover, you can keep your VS Code installation up to date, whereas the Server version is updated by OSC (and rather irregularly so).
- The same setup also works for Positron, an R (and Python) IDE that is built on VS Code.
We will set up two connections: one to a compute node, which is the one you should normally use, and one to a login node, as a fallback. Connecting to a compute node takes more setup, but avoids running VS Code (and anything you do in its terminal) on a login node.
2 Install VS Code and the Remote Development extension
Install VS Code on your own computer:
“Regular” installation instructions for Windows / Mac / Linux.
If you are using an OSU computer, you may not have the required “administrative privileges” to install software on your computer the regular way. However, you should in that case have an OSU application on your computer that allows you to install a selection of approved software, and that selection should include VS Code. On Windows, this app is called “Software Center” and on Mac, it is called “Ohio State Application Self Service”.
Open VS Code and install the “Remote Development extension pack”: open the Extensions side bar and search for it there. Once you found it, click on its
Installbutton like you’ve done previously with other extensions.Open a terminal in VS Code (
Terminal>New Terminal): you’ll need it in the steps below.
3 Set up the OSC connections
3.1 The SSH configuration file
Open the VS Code Command Palette (F1 or Ctrl/⌘+Shift+P) and start typing “remote open”:
- Select “Remote-SSH: Open SSH Configuration File…”
- Then, select the top option, a file that contains the username you have on your computer and ends in
.ssh/config
Paste the following into the SSH configuration file that opens:
Host osc-pitzer-login User <osc-username> HostName pitzer.osc.edu Host osc-pitzer-compute User <osc-username> ForwardAgent yes StrictHostKeyChecking no UserKnownHostsFile=/dev/null ConnectTimeout 120 ProxyCommand ssh -o LogLevel=QUIET -o BatchMode=yes osc-pitzer-login ./osc-compute-proxy.shThese instructions are for Windows, click “Mac” above to see the Mac instructions. (The only difference is the path to the
sshprogram in the last line.)Host osc-pitzer-login User <osc-username> HostName pitzer.osc.edu Host osc-pitzer-compute User <osc-username> ForwardAgent yes StrictHostKeyChecking no UserKnownHostsFile=/dev/null ConnectTimeout 120 ProxyCommand C:/Windows/System32/OpenSSH/ssh.exe -o LogLevel=QUIET -o BatchMode=yes osc-pitzer-login ./osc-compute-proxy.shIn both instances, change
<osc-username>to your OSC username, e.g. toUser jane. Then, save the file.
It defines two remote “hosts” at OSC that you can connect to:
osc-pitzer-loginconnects to a login node of OSC’s Pitzer cluster.osc-pitzer-computeconnects to a compute node of OSC’s Pitzer cluster. You can’t connect directly to a compute node, so this connection first goes to a login node, and there runs a script (osc-compute-proxy.sh, see below) that requests a compute job and then passes on the connection to the compute node you’ve been assigned.
3.2 Avoid being prompted for your OSC password
Next, you’ll set up an “SSH key pair”, which lets OSC recognize your computer so you won’t be prompted for your password. This is required for the compute node connection, and convenient for the login node connection and any other SSH connection to OSC.
In the VS Code terminal (regardless of whether you’re using Windows or Mac), generate an SSH key pair:
ssh-keygen -t rsaYou’ll get some output and will then be asked several questions, but in each case, you can just press Enter to select the default answer.
Transfer the public key to OSC, replacing
<user>with your OSC username. You’ll be prompted for your OSC password.# Replace <user> by your username, e.g. "ssh-copy-id jelmer@pitzer.osc.edu" ssh-copy-id <user>@pitzer.osc.edu# Replace <user> by your username, e.g. "jelmer@pitzer.osc.edu" cat ~/.ssh/id_rsa.pub | ssh <user>@pitzer.osc.edu 'mkdir -p .ssh && cat >> .ssh/authorized_keys'Test it: the following should print the name of a Pitzer login node, without asking for your password:
ssh osc-pitzer-login hostname
3.3 The proxy script at OSC
The compute node connection runs a short “proxy script” in your Home dir at OSC. Copy it there by running the following command in your VS Code terminal:
ssh osc-pitzer-login 'cp /fs/ess/PAS3493/share/osc-compute-proxy.sh ~/ && chmod +x ~/osc-compute-proxy.sh'This script contains the following:
#!/bin/bash
exec salloc --quiet -A PAS3493 -t 300 bash -c 'nc $SLURM_NODELIST 22'That is, it requests a compute job (salloc) for 300 minutes (5 hours) with the course’s OSC Project PAS3493, and then connects to the compute node you were assigned (nc ... 22).
Once the course is over, you should no longer use the course’s OSC Project. To change the Project, or the duration of your compute jobs, open ~/osc-compute-proxy.sh at OSC and edit PAS3493 and/or 300.
3.4 Increase the connection timeout
Because it can take a little while to get a compute job, you also need to increase the time VS Code will wait for a connection: open the VS Code Settings ( > Settings), search for remote.SSH.connectTimeout, and change its value from 15 to 300 (seconds).
If the above setup didn’t work for you, try this:
In the SSH configuration file, change the
ProxyCommandline forosc-pitzer-computeto:ProxyCommand /Users/<computer-username>/.ssh/osc-compute-proxy.sh %hProxyCommand C:/Users/<computer-username>/.ssh/osc-compute-proxy.cmd %hwhere
<computer-username>is your username on your computer (it’s also in the path to the SSH configuration file).Create the proxy script by running the following in the VS Code terminal:
cat > ~/.ssh/osc-compute-proxy.sh << 'EOF' #!/bin/bash exec ssh -o LogLevel=QUIET -o BatchMode=yes osc-pitzer-login \ "/usr/bin/salloc -A PAS3493 -t 300 /bin/bash -c 'nc \$SLURM_NODELIST 22'" 2>/dev/null EOF chmod +x ~/.ssh/osc-compute-proxy.shThis assumes you are using PowerShell, the default Windows shell in VS Code (you should see “PowerShell” in the top right of the terminal). If you are using Git Bash or WSL, use the Mac instructions instead.
@' @echo off ssh -o LogLevel=QUIET -o BatchMode=yes osc-pitzer-login "/usr/bin/salloc -A PAS3493 -t 300 /bin/bash -lc 'nc $SLURM_NODELIST 22'" '@ | Out-File -Encoding ascii "$env:USERPROFILE\.ssh\osc-compute-proxy.cmd"
To also connect to Cardinal or Ascend, add additional entries to the SSH configuration file in which you replace pitzer by cardinal or ascend. (For the compute node connection, the ProxyCommand line should then refer to the matching login host, e.g. osc-cardinal-login.)
4 Connect to OSC
4.1 Connecting
Open the Command Palette (F1 or Ctrl/⌘+Shift+P), start typing “SSH connect”, and click on
Remote-SSH: Connect to Host...Select
osc-pitzer-compute.A new VS Code window will open. The connection may take a little while (typically 5–30 seconds, but longer when OSC is busy), because a compute job has to be requested and started.
- If you’re asked about the operating system of the host, select Linux.
- If you’re asked whether you “Trust the Authors” of the folder, click “Yes”.
- If there is a pop-up in the bottom-right asking you to update Git, click “No” and check “Don’t show again”.
Like you’ve seen with VS Code Server, the program’s default location is your Home dir, and it is best to change this using
File>Open Folder: go to your/fs/ess/PAS3493/people/$USERdir.
Try the osc-pitzer-login connection instead, which is less likely to fail and is faster to connect to.
However, VS Code then runs on a login node rather than on a compute node, so you should avoid running any analyses directly in the terminal. On top of that, VS Code itself takes up resources on the login node, and OSC prefers that you don’t do this.
4.2 Connecting from now on to previously opened folders
Conveniently, VS Code will remember folders that you’ve opened this way, and show them on the “Welcome” tab that is always displayed when you open the program. Test this:
- Completely quit VS Code.
- Open it again, and under “Recent” on the Welcome tab, look for your folder in
/fs/ess/PAS3493/, and click on that to connect to OSC and open that folder!