How to use Visual Studio Code (VSCode) to edit files on your Linux server
Using Visual Studio Code to Edit Files on a Linux Server
Visual Studio Code is a lightweight text editor developed by Microsoft, making it an excellent tool for editing configuration files on your Linux server. This guide explains how to set it up and use it effectively.
Note: Visual Studio Code is distinct from "Visual Studio"; they are entirely different tools!
One of Visual Studio Code's strengths is its extensive marketplace of extensions that enhance its functionality. One such extension is Remote-SSH, which enables seamless editing of files on remote servers.
Setting Up Visual Studio Code
Visual Studio Code is available for Windows, macOS, and Linux. Begin by downloading and installing it from the official website.
After installation, you will see the “Welcome” screen:
Verifying SSH Requirements
The Remote-SSH extension requires an SSH client installed on your local machine (your Linux server already has an SSH server). To check if SSH is installed, open a command prompt/terminal and type ssh. If you see usage instructions, you're all set. Otherwise, you’ll need to install an SSH client.
Installing SSH Clients
- Windows:
On Windows 10 (Build 1803 or higher), enable the built-in OpenSSH Client:
Open Settings from the Start Menu.
Navigate to Apps > Apps and Features > Manage Optional Features.
Click Add A Feature, search for OpenSSH Client (not OpenSSH Server), and click Install.
For older versions, install an SSH client via Git for Windows.
- macOS:
SSH is pre-installed.
- Linux:
- Debian/Ubuntu: Run sudo apt-get install openssh-client.
- RHEL/CentOS/Fedora: Run sudo yum install openssh-clients.
Re-test the ssh command after installation. If it’s still unrecognised, try logging out and back in.
Installing the Remote-SSH Extension
Once SSH is ready, install the Remote-SSH extension. Visit the extension page and click Install, which will open the Extensions page in Visual Studio Code.
Click the blue Install button to add the extension. This process only takes a few moments and doesn’t require restarting Visual Studio Code.
Connecting to Your Server with Remote-SSH
Press F1 or Ctrl + Shift + P ( Cmd instead of Ctrl on macOS).
Type remote-ssh connect and select Remote-SSH: Connect to Host....
Choose + Add New SSH Host... and enter the connection command in the format ssh user@ip.address (e.g., ssh root@185.195.238.100). Don't know your Linux SSH details? Take a look at our Logging Into Your Linux VPS guide.
When prompted, enter your password and confirm the server's fingerprint by clicking Continue.
||| Replace the IP address with your own servers IP address.
Editing Files
Once connected:
- Open files or folders via File > Open.
- Edit files as you would in any text editor.
- Save your changes via File > Save.
The Remote-SSH extension remembers your server, so next time you select Remote-SSH: Connect to Host, your server will appear as an option.
Enjoy efficient server file editing with Visual Studio Code!
Updated on: 30/11/2024
Thank you!