How To Code on a Remote Server Using VSCode

Editing on a remote server is a pain in the ass

Whether you are a machine learning researcher tweaking paramaters on a cloud server or if you are coding on a local docker or virtualbox instance, there are too many inconveniences to deal with.

For example:

  • SSH connection loss
  • Very slow connection
  • No file search (unless using bash commands)
  • No text search in diretory (unless using bash commands)
  • Different shell, commands, and scripts

Sometimes, you may contemplate replicating the entire server environment locally to utilize your local tools and development environment. However, it can be expected to not work perfectly, and you will experience lots of issues, unless you are running the same versions of the OS and tools as the original server.

This is something I learned the hard way in the Operating Systems course I am currently taking. It is not worth spending hours trying to debug random obscure c errors and matching versions when there is a much simpler and universal solution available.

Prerequisites

Install VSCode

1. Install Remote SSH plugin

Install Remote - SSH extension

2. Connect to host

Press F1 (Fn+F1 on mac) and type "Connect to host"

connect to host

Enter your username and server address and password if needed.

Configure ssh hosts for faster access

Save your commonly used ssh connections to the ssh config file for faster access.

First, open up the config file

vim ~/.ssh/config

and enter your server and username in following format

Host waterloo
    HostName linux.student.cs.uwaterloo.ca  
    User dverma

Now, you can just type ssh waterloo instead of ssh dverma@linux.student.cs.uwaterloo.ca

3. Edit files

You should now notice a new window open and you will see that you are connected to the server by observing the bottom left of your window. remote ssh icon

Now, you can just simply type cmd+o to open any file or folder on the remote server.

Conclusion

Despite being fluent in vim and obsessive about optimizing terminal workflow and productivity, I've noticed that I have more output using simple text editors. There is just so much more convenience offered right out of the box. You can just simply focus on coding with minimal tweaking of config files.

Last Updated: 9/10/2019, 5:20:48 PM