VSCode (and Cursor)
Using SSH with VSCode and Cursor
PLEASE NOTE:
Our scope in supporting the Visual Studio Code editor is limited. If we confirm that SSH works outside of VS Code, and the following settings do not resolve your issue, we will suggest you cleanly remove and reinstall the application.
Also note that for the purposes of this documentation, VSCode and Cursor will be used interchangeably, unless there are specific noted differences.
VSCode and Cursor are used with the extension “Remote - SSH,” which must be installed before any of the following is relevant. VS Code can use either a “remote folder” or a git repo in a remote filesystem, but they both connect using the Remote - SSH extension.
Visual Studio Code: Remote-SSH has multiple moving parts. To answer common questions and issues, please familiarize yourself with the information below.
Getting started
Install Visual Studio Code or Cursor from their websites, then do one of the following:
- From the left sidebar, choose ‘Extensions’
- In the command palette (Ctrl-Shift-P or Cmd-Shift-P), type ‘Extensions’ and choose ‘Extensions: Install Extensions’
Search for and install the Remote - SSH extension.
Configuration
First and foremost, if you are using Linux or macOS on your local computer, make sure you have the CSAIL ssh configuration set up, and optionally CSAIL Kerberos for passwordless authentication. If you are using Windows, simply continue.
PLEASE NOTE:
VSCode and Cursor on Windows do not directly support SSH control sockets, meaning that connections cannot be shared, and you may be required to complete Duo two-factor authentication more often than you would on Linux or macOS. There isn’t anything we can do about this; the ‘Use Local Server’ setting below may or may not help.
Once that’s done, open the VSCode user settings, then search for ‘Remote.SSH’.
You’ll need to set the following settings:
- Lockfiles in Tmp: true (only for VSCode)
- Server Install Path: for every CSAIL server you connect to, you’ll
need to add a line here.
- The ‘item’ will be the name of the server,
for example
group-server.csail.mit.edu
- The ‘value’ will be
/tmp/.vscode.<your CSAIL username>
or/tmp/.cursor.<username>
depending on which you use, for example/tmp/.vscode.acloss
or/tmp/.cursor.acloss
.
- The ‘item’ will be the name of the server,
for example
- Show Login Terminal: true
- Use Local Server: true
NOTE: If you do not the set the ‘Server Install Path’ correctly for ALL of the hosts you connect to, you WILL encounter issues using VSCode or Cursor.
You shouldn’t need to set these, but good to know:
- Remote Platform
- Windows/Linux/macOS, will almost always be Linux at CSAIL
You should then be able to use the command palette to select
‘Remote-SSH: Connect to Host’ using the full host name, for example
<your CSAIL username>@group-server.csail.mit.edu
. You’ll be prompted
for Duo two-factor authentication in the terminal at the bottom of the screen,
and once completed, you’ll be able to access your compute resources.
As always, if you have any trouble, contact TIG at help@csail.mit.edu
Previous/additional VSCode documentation
Note that the below shouldn’t be needed to use VSCode/Cursor, but are here for more context (and in case the above don’t work for you).
Lockfiles
When connecting to a remote, VS Code will prompt the user for an ssh password. When the
ssh session is open, vscode will create-if-not-exists $HOME/.vscode-server
, create a lockfile,
and upload whatever data it wants to put on the remote.
In the event you are writing your files to your AFS home directory, vscode will be unable
to create a lockfile there. Setting Lockfiles In Tmp
to True will be required (see below).
Different error messages are possible depending on whether vscode has successfully written
to your home directory before. This may falsely appear to be an authentication error.
.vscode-server directory
If you are writing to a .vscode-server
directory in AFS, it is possible that vscode will disconnect
or appear to hang while file operations on the remote. This may be due to a very large number of
files being accessed by vscode-server resulting in a slow response
If your only option is AFS, you may be able to delete the .vscode-server
directory as a temporary fix.
but you may still encounter performance-related issues in the future as it indexes your data.
If the remote host has a filesystem appropriate for your use, then you can choose a directory and add the host to the Server Install Path map (see below), so vscode can be installed without AFS.
Remote Execution
When you connect using VS Code Remote-SSH, it starts a node
process on the remote system. This
process stays running after you disconnect. See the VS Code Remote Development documentation.
This has implications for some things that rely on events that occur at login, such as updating group membership and obtaining tokens for AFS filesystem access. If you find that something works once, but fails after starting a new connection later, that’s a good clue that this could be involved.
If you have an issue related to the remote server, you should try running Kill VS Code Server on Host
(see below) and if that does not resolve the issue, please also try closing all local vs code processes
before connecting outside vs code in a terminal, then searching for .vscode-server processes and
terminating each. (also below)
Configuration notes
⌘+Shift+P
or Ctrl+Shift+P
opens the “Command Palette”
Use the command palette to search for the following options as needed:
-
Remote-SSH: Settings
-
Lockfiles In Tmp: must be ‘true’ to work around afs home directories.
-
Server Install Path: alternate .vscode-server paths on a per-host basis
- set "Item" to the long hostname of the remote host, including `.csail.mit.edu`
- set "Value" to the directory where `.vscode-server` should be created
Do not set Server Install Path to /tmp, /scratch, or a similar shared directory on a shared server. It should be a directory no one else will choose.
-
Remote-SSH: Open Configuration File
-
Use this for your SSH config settings (e.g. aliases or jump host)
-
Remote-SSH: Kill VS Code Server on Host
-
Eliminates old processes on the server that may be causing issues
-
Close local VS Code first if it is running
-
You can also ssh using a terminal (not inside vscode) and do:
- `ps ux | grep .vscode-server | awk '{print $2}' | xargs kill`
Reinstalling Visual Studio Code
If these suggestions fail and VS Code still has unexplained behavior, we can follow Microsoft’s clean reinstall instructions to delete all settings and user data and reinstall the application:
If you want to remove all user data after uninstalling VS Code, you can delete the user data
folders Code and .vscode. This will return you to the state before you installed VS Code.
This can also be used to reset all settings if you don't want to uninstall VS Code.
The folder locations will vary depending on your platform:
- Windows - Delete `%APPDATA%\Code` and `%USERPROFILE%\.vscode`.
- macOS - Delete `$HOME/Library/Application Support/Code` and `~/.vscode`.
- Linux - Delete `$HOME/.config/Code` and `~/.vscode`.