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

Usama AijazUsama Aijaz
4 min read

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)

  1. Open VS Code.

  2. Go to Extensions (Ctrl + Shift + X).

  3. 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)

  1. Open Command Palette: Ctrl + Shift + P

  2. Run:

     Remote-SSH: Connect to Host...
    

    Here is image which shows this.

  3. 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

  1. Click File > Open Folder.

  2. Choose any path like /home/devuser/projects/my-app.

  3. 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.


0
Subscribe to my newsletter

Read articles from Usama Aijaz directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Usama Aijaz
Usama Aijaz