Editing Files in a Remote Linux Machine or VM Using VS Code (Host Linux)

Table of contents
- π οΈ Prerequisites
- π Step 1: Ensure SSH Access from Host to Remote
- π§ͺ Step 1.1: Verify SSH on Remote
- π Step 1.2: (Optional) Set Up SSH Key Auth
- π Step 2: Configure SSH for Simplicity
- π§© Step 3: Install Remote - SSH Extension
- π Step 4: Connect to Remote in VS Code
- π Step 5: Open and Edit Remote Files
- β Why This Setup is Awesome
- π§ Final Thoughts
When working with remote Linux machines or virtual environments (like VMs, cloud servers, or Docker hosts), one common need is to edit files inside the remote system using VS Code running on your local machine. This setup is especially handy if your host OS is Linux and you want to keep everything tightly integrated.
Thanks to VS Codeβs Remote - SSH extension, you can connect to a remote machine and work with files directly β without needing to copy anything over manually.
π οΈ Prerequisites
Host machine (your local Linux system): Any Linux distribution (e.g., Ubuntu, Fedora)
Remote machine (guest VM / remote server): Any Linux-based system (on KVM, VirtualBox, cloud, etc.)
SSH access between the two machines
VS Code installed on the host
OpenSSH server running on the remote
π Step 1: Ensure SSH Access from Host to Remote
π Do this on your host machine
Try connecting to the remote system via SSH:
# use your hostname and ip
devuser@192.168.100.50
If SSH isnβt working, continue with the checks below.
π§ͺ Step 1.1: Verify SSH on Remote
π Do this on the remote machine (VM/server)
Check IP:
ip a
Install and start SSH server:
sudo apt install openssh-server -y
sudo systemctl enable --now ssh
π Step 1.2: (Optional) Set Up SSH Key Auth
π Do this on the host machine
If you want password-less access, generate a key and copy it:
ssh-keygen -t rsa -b 4096
ssh-copy-id devuser@192.168.100.50 #if this command does not work do below
Then cat id_rsa.pub file like below.
cat ~/.ssh/id_rsa.pub # this is host machine step host machine
Copy Return output of public key then past it into guest machineβs authorized_keys file under .ssh folder
#These are guest machine's step
nano ~/.ssh/authorized_keys # add key here if authorized_keys file not present it will also create this
Give these permissions to file and folder
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
π Step 2: Configure SSH for Simplicity
π Do this on the host machine
Edit or create your SSH config file:
nano ~/.ssh/config
Add the following block:
Host dev-vm # or use same ip of your host like this "Host 192.168.100.50"
HostName 192.168.100.50
User devuser
IdentityFile ~/.ssh/id_rsa
Save file with ctrl x then press y then enter.
π§© Step 3: Install Remote - SSH Extension
π Do this on the host machine (inside VS Code)
Open VS Code.
Go to Extensions (
Ctrl + Shift + X
).Search for and install: Remote - SSH.
Here is screenshot below shows the extension:
π Step 4: Connect to Remote in VS Code
π Do this on the host machine (inside VS Code)
Open Command Palette:
Ctrl + Shift + P
Run:
Remote-SSH: Connect to Host...
Here is image which shows this.
Choose:
dev-vm or whatever your hostname or ip instead of name if you use ike 192.168.100.50
VS Code will SSH into the remote machine and set up its server component.
π Step 5: Open and Edit Remote Files
π Do this inside the new remote VS Code window
Click
File > Open Folder
.Choose any path like
/home/devuser/projects/my-app
.Start editing β VS Code handles everything remotely.
β Why This Setup is Awesome
Edit and run code inside your VM/server while using VS Code locally.
No file copying, syncing, or mounts needed.
Full access to terminals, Git, debugging, extensions, etc.
Works great for:
Local virtual machines
Remote dev servers
Cloud instances (AWS, GCP, etc.)
Internal lab or test environments
π§ Final Thoughts
Whether you're connecting to a VM, a cloud instance, or a dev box, VS Code + SSH turns remote coding into a smooth, native experience. You get the best of both worlds: local tooling with remote execution.
Subscribe to my newsletter
Read articles from Usama Aijaz directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
