DEV Community

Rahul
Rahul

Posted on

How to use VS Code for remote development behind corporate network

The basic setup is like this:

  1. your workstation <=> remote server/workstation
  2. your workstation <=> a jump host <=> remote server/workstation

VS code will ssh into the remote server and you can open your development folder. It would be as if the files are in your local machine.

Case 1 is pretty straight forward. If you do not have a jump host in between then go to step 2.
For Case 2, you need to create a tunnel.

Step 1.

Creating a tunnel.

ssh -i <private key> <jump host username>@<jumphost> -L localhost:22:<remote_server>:22 
Enter fullscreen mode Exit fullscreen mode

private key is the one whose public pair is added to the jump host. What this does is that it creates a tunnel and informs ssh to send the traffic on port 22 of localhost to port 22 of remote_server.

After this you should easily be able to login to your remote_server

ssh <remote server username>@localhost
Enter fullscreen mode Exit fullscreen mode

Step 2:

Create an ssh pair if you don't already have one.
Now login to remote ssh server, and edit ~/.ssh/authorized_keys and paste the contents of .pub file.
*.pub is a public file that you are sharing with the server. Do not share the private key with anyone. The private file with have private mentioned in it, public won't.

This allows you to ssh from your local to server without entering password.

Step3:

Make sure you have installed VS code and have Remote-SSH extension installed.

Step 4

Now we need to create a config file that will tell VS code to use the ssh file when logging in to the remote server.

$ cat config
Host localhost
  HostName localhost
  IdentityFile C:\Users\<user>\.ssh\<id_rsa>
  User <user name for remote>
Enter fullscreen mode Exit fullscreen mode

IdentityFile is the location of private file.
Save it.

Step5

Add config file to VS code extension settings.
In settings, type: @ext:ms-vscode-remote.remote-ssh
In Remote SSH: Config File
enter the absolute path of the config file we created in Step 4.

Step 6.

Now we need to connect. Click on lower green button "><" that says "open a remote window"
It will open the usual context menu.
"Remote-SSH: Connect to remote Host..."
type: remote_username@localhost

This will establish a connection to your remote server and install VS code terminal. It will ask which machine. Select from Linux, Windows, Mac. After that you are ready.

Installing VS code server needs internet connection, so if your server has internet connection off then you need to follow step 7.

Step 7. Manually setup VS code on remote server

ssh to remote server.
Download the latest server package from https://update.code.visualstudio.com/latest/server-linux-x64/stable

SCP the file to the server.

$ cd ~/.vscode-server/bin/
5763d909d5f12fe19f215cbfdd29a91c0fa9208a  # <-- is the commit id
# delete all the files in this directory
$ tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1
Enter fullscreen mode Exit fullscreen mode

Follow Step 6 again.
You are now ready to for development ready.

Please mention if any step was not clear. I would have attached images but Dev doesn't support uploading images (teach if you know how to).

Follow me on @ask_rpc.

Top comments (0)