VS Code Connect to Remote Server over Intranet
This post is a walkthrough to setup and connect Visual Studio Code to remote server over Intranet or behind a firewall.
Prerequisite
- Local machine: A computer/laptio running Debian Linux or Windows
- Intermediate jump box:
- OS: Debian Linux
- IP: <jump_box_IP>
- SSH Port: 12345
- Remote target box:
- OS: Debian Linux
- IP: 192.168.1.100
- SSH Port: 23456
1. Install VS Code in Server
Download VS Code from the download page. For Debian, download the .deb package (64-bit), and install with:
$ sudo apt install ./code_<version>_amd64.deb
Note: Installing the .deb package will automatically install the apt repository and signing key to enable auto-updating using the system’s package manager.
Launch the VS Code application and keep it running. Now it works as the VS Code Server.
2. Install and Setup VS Code locally
(1) Download and Install VS code
Download and install VS Code installation package according to working computer.
(2) Install OpenSSH Client
- For Debian
sudo install openssh-client
- For Windows
Follow the instructions in Get started with OpenSSH for Windows.
(3) Generate user SSH key pairs
ssh-keygen -t ed25519
Note:
SSH default directory:
- For Debian:
~/.ssh
- For Windows:
~/Users/username/.ssh
Transfer loca user SSH public key to jump box:
ssh-copy-id -p 12345 username@jump_box_ip
With similar operation, Generate user SSH key pairs in the jump box and transfer public key to remote server.
(4) Install the Remote-SSH
extension
Search for “remote ssh” in the Extensions
view (Ctrl+Shift+X). After the extension installed, there will be an indicator on the bottom-left of the Status bar, and a Remote Explorer
icon at the left Activity Bar
:
(5) Edit local SSH config
file
Edit SSH config file .ssh/config
in local machine, append these contents:
# Jump box with public IP address
Host jump-box
HostName <IP address of jump box>
User <username>
IdentityFile ~/.ssh/id_ed25519
# Target machine with private IP address
Host target-box
HostName 192.168.1.100
User <username>
IdentityFile ~/.ssh/id_ed25519
ProxyCommand ssh -q -W %h:%p jump-box
Note: If
IdentifyFile
were not provided, you have to input password manually.
3. Connect local machine to remote host
(1) In local machine, run VS Code.
(2) Click Remote Explorer
icon in the left Activity bar
, it will show jump-box
and ’target-box’ under SSH
.
(3) Click the ‘->’ behind jump-box
and target-box
in turn.
(4) If there were no error, the local VS Code has connected to the remote server.
4. Close remote connection
Click the VS Cide main menu File - Close Remote Connection
to disconnect from the remote host.
5. VS Code alternatives
Beside VS Code, other similar code editors are available:
- VSCodium: Free/Libre Open Source Software Binaries of VS Code. These binaries are licensed under the MIT license. Telemetry is disabled.
- code-server: VS Code in the browser.