When working on a development project in the tech field, you often interact with remote servers. I ofen used to face difficulties in moving files and connecting to remote servers on Windows or Mac OS then I came across Visual Studio Code Remote - SSH. In this post I will show you how to connect to a remote server using SSH with Vscode and move files easily between your local computer and the remote server.
Content:
From Vscode docs:
The Visual Studio Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code’s feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem.
Source: Vscode docs.
I have created an instance on my univeristy’s (unimelb) cloud platform as illustrated in the figure below. I will be using the test
instance for today where we will connect to the instance using vscode remote ssh. I have setup the instance with my public ssh key.
Note: You can use any cloud platform as the basics would be the same. You would need your public key on the remote server (under authorized keys)
SSH with Vscode
At this stage, I assume you have an instance you want to connect and your public key resides on the server gaining you acess to it. Now using vscode to connect to the server can be done in 3 simple steps as shown below.
Step 1: Install extension
You have to first install the vscode extension for remote-ssh. You can do so by search for ssh
in the extensions and installing the extension as shown below.
Step 2: Add host to ssh config
Once the extension has been installed an icon will be pop up on the left side menu where you can establish a new connection to a remote server (host) as shown below.
Now click on add new host and enter the ssh command for connecting to the remote server and pointing to your ssh key. Choose the config file you want to add the host to.
Step 3: Connect to host
The remote server (host) should be added to the list. In order to connect you can right-click and choose from the options based on you preference.
Done! you can now connect your remote server and use its terminal in vscode.
Moving files
One of the great features of this extension is not requiring the use of another tool to move files between the remote server and your local machine.
Uploading files to remote server
Uploading files to remote servers can be easily done by simply dragging files to the vscode ui (under ssh) as shown below.
Downloading files from remote server
Downloading files from remote servers can be easily done too by simply right-clicking and choosing download from the vscode ui as shown below.
You can check out additional features from the docs (link here).
Happy remote coding!
Leave a comment