Connecting Visual Studio Code to Server via SSH
Use visual Studio Code instead of Nano. Connect the code editor to its remote server via SSH in just a few steps.
Table of Contents
CAUTION
Please note that initially, I wrote this blog post in German. This translation is for your convenience. Although every effort has been made to ensure accuracy, there may be translation errors. I apologize for any discrepancies or misunderstandings resulting from the translation. I am grateful for any corrections in the comments or via mail.
The problem with the terminal
The โnormalโ way to connect to one is via SSH. The easiest way to do this is with a terminal (Link to the Microsoft Terminal).
Suppose this is not possible (of course, with the IP address of your own server). In that case, you must check whether SSH is installed on the server and the device you want to establish the connection with.
In Windows, we look for the menu for โoptional featuresโ and open it.
Here is the OpenSSH client
If the OpenSSH client does not appear in the list, it must be added (not to be confused with the OpenSSH server, which should be installed on the server).
At this point, I took the opportunity to say goodbye to Internet Explorer ๐
There is not much to see as soon as you have logged in to the server.
The folders can be displayed with ls
. But this way you can only see the folders or files in the directory you are currently in.
Of course, programs such as tree can also display an overview of all folders and subfolders if you install it beforehand via apt install tree
. At the latest when you want to edit files, however, it becomes cumbersome again.
cd docker
nano docker-compose.yml
Alternatively also vim docker-compose.yml
You can exit Vim again by typing :q.
With larger files I lose the overview in these text editors.
VSCode as a solution
It is also possible to establish an SSH connection to the server via VS Code recently. The prerequisite for this is that the program is installed on the computer. In contrast to Visual Studio (without code), this is a free program from Microsoft.
Visual Studio Code](https://code.visualstudio.com/) is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.
When you start Visual Studio Code, it looks relatively unspectacular.
Using the extensions ( Ctrl + Shift + X ) we search for the extension remote ssh and install it. Press F1 or Ctrl + Shift + P to open the command line. We search for SSH and select โRemote-SSH: Connect to Host โฆโ
Enter username@ip-address
in the field that pops up. A new VSCode window opens with a query about whether Linux, MacOS or Windows is on the server. Linux should be the correct answer in most cases. You will then be asked for the password.
Now we press Open folder in Explorer and select โ/home/username/โ in the new field.
You will then be asked for the password again. Once you have entered it, you will see the serverโs folder structure.
It is then also possible to create and edit your own files in a more beautiful and, in particular, feature-rich editor.
However, you should be careful as it is easier to accidentally delete your files.