VSCode remote tunnels
29-11-2023
To decrease friction when developing code that must run on a remote server, it can be helpful to use Remote Development tools like VSCode’s Remote Development Pack. In the past, we’ve used the Remote - SSH extension, but due to security considerations, that extension will not work on our servers (it requires TCP port-forwarding, which we disallow).
Instead, it is now recommended that we use Remote - Tunnels.
Installation
Server Installation
You will need to have the VSCode executable installed on the server. You can do this by installing the VSCode CLI for the relevant operating system / flavour. https://code.visualstudio.com/docs/setup/linux
You can confirm installation by running:
code --version
Client Installation
In VSCode desktop on your local machine, install the Remote - Tunnels extension.
Running a Tunnel
Whenever you want to connect to a server via tunneling, you will need to make sure that the server is running a tunnel and that the client is authenticated.
Server Configuration
On the server, run:
code tunnel --accept-server-license-terms Note, your first connection will require you to authenticate with GitHub. A full example is shown below:
[admlmiloszewski@lddevfiorcdc1 ~]$ code tunnel --accept-server-license-terms
-
- Visual Studio Code Server
-
- By using the software, you agree to
- the Visual Studio Code Server License Terms ([https://aka.ms/vscode-server-license)](https://aka.ms/vscode-server-license)) and
- the Microsoft Privacy Statement ([https://privacy.microsoft.com/en-US/privacystatement).](https://privacy.microsoft.com/en-US/privacystatement).)
- To grant access to the server, please log into [https://github.com/login/device](https://github.com/login/device) and use code 1234-5678
For future runs, when you start the tunnel you will have the option to open the connection in your browser (via vscode.dev). You don’t need to follow this link. The server is ready to accept new client connections, so you can open the connection in VSCode desktop on you local machine. A full example is shown below:
[admlmiloszewski@lddevfiorcdc1 ~]$ code tunnel
-
- Visual Studio Code Server
-
- By using the software, you agree to
- the Visual Studio Code Server License Terms ([https://aka.ms/vscode-server-license)](https://aka.ms/vscode-server-license)) and
- the Microsoft Privacy Statement ([https://privacy.microsoft.com/en-US/privacystatement).](https://privacy.microsoft.com/en-US/privacystatement).)
- Open this link in your browser [https://vscode.dev/tunnel/lddevfiorcdc1ny1ninetyonecom](https://vscode.dev/tunnel/lddevfiorcdc1ny1ninetyonecom)
Note, it may be useful to run the above command in the background to give you access to your shell.
Client Configuration
In VSCode desktop on your local machine, you should be able to select your server from Remote Explorer (from the Development Pack). You will be prompted to connect your GitHub for the first connection.