VS Code Server on O2

 

This page shows you how to install and run VS Code using your local browser. Let us know if you have any questions.

Log on to O2

If you need help connecting to O2, please review the Using Slurm Basic and the How to Login to O2 wiki pages.

From Windows, download and install MobaXterm for Windows: https://mobaxterm.mobatek.net/,to connect to o2.hms.harvard.edu and make sure the port is set to the default value of 22.

From a Mac Terminal, use the ssh command, inserting your HMS Account instead of user123:

1 2 3 export PORT=51234 # Please choose a port between 50000 to 60000 for yourself using the command 'netstat' in a local terminal. Select a port that says 'listening' or 'established'. export CLUSTER_USER=YourHMSID ssh -L $PORT:127.0.0.1:$PORT $CLUSTER_USER@o2.hms.harvard.edu

Install VS Code Server under your account and test it out

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 export PORT=51234 srun --pty -p priority -t 8:0:0 --tunnel $PORT:$PORT bash mkdir -p ~/.local/lib ~/.local/bin curl -fL https://github.com/cdr/code-server/releases/download/v3.12.0/code-server-3.12.0-linux-amd64.tar.gz | tar -C ~/.local/lib -xz mv ~/.local/lib/code-server-3.12.0-linux-amd64 ~/.local/lib/code-server-3.12.0 # Start code server ~/.local/lib/code-server-3.12.0/bin/code-server # You should see output: $ [2021-10-05T13:58:56.961Z] info code-server 3.12.0 4cd55f94c0a72f05c18cea070e10b969996614d2 [2021-10-05T13:58:56.962Z] info Using user-data-dir ~/.local/share/code-server [2021-10-05T13:58:56.995Z] info Using config file ~/.config/code-server/config.yaml [2021-10-05T13:58:56.995Z] info HTTP server listening on http://127.0.0.1:51234 [2021-10-05T13:58:56.995Z] info - Authentication is enabled [2021-10-05T13:58:56.995Z] info - Using password from ~/.config/code-server/config.yaml [2021-10-05T13:58:56.995Z] info - Not serving HTTPS # Command + click the "http://127.0.0.1:51234" to open the link # Then copy and paste the password to browser cat ~/.config/code-server/config.yaml

Directly login, run interactive job and start VS Code Server from local machine

1 2 3 4 5 6 7 8 9 10 11 # Set DUO default to push if you didn’t do it yet. # Run this command on O2: echo 'export DUO_PASSCODE=push’ >> $HOME/.bashrc # On your local machine # set up alias. You could add this row to your ~/.bash_profile alias vscode='PORT=51234; CLUSTER_USER=YourHMSID; ssh -L $PORT:127.0.0.1:$PORT $CLUSTER_USER@o2.hms.harvard.edu -t "hostname; echo port is: $PORT; kill -9 $(/usr/sbin/lsof -t -i:$PORT) 2>/dev/null; srun --pty -p priority -t 8:0:0 --tunnel $PORT:$PORT bash -c \"hostname; echo port is: $PORT; kill -9 $(/usr/sbin/lsof -t -i:$PORT) 2>/dev/null; export PORT=$PORT; ~/.local/lib/code-server-3.12.0/bin/code-server & bash;\""' # login to O2, start interative job and run vs code server vscode

port 51234 is in use or unavailable"? Make sure you close the VS Code editor page within your browser

1 2 3 4 5 6 7 8 9 10 11 12 # If you see this error: channel 3: open failed: connect failed: Connection refused channel 3: open failed: connect failed: Connection refused login03.o2.rc.hms.harvard.edu port is: 51234 port 51234 is in use or unavailable Connection to o2.hms.harvard.edu closed. Make sure you close the VS Code editor page with your browser



Please contact us if you have any questions/comments.