Have you ever thought about using VS Code while accessing your virtual machine? This blog covers how to do that. By connecting your virtual machine with VS Code, you can leverage the features of both.
Prerequisites:
You should have some knowledge of VS Code and virtual machines. The following are needed:
- VS Code
- Git
- VirtualBox
- Virtual machine
- Vagrant
In this guide, an Ubuntu virtual machine is used. To set up your Ubuntu virtual machine, click here.
Getting Started:
Starting up the Virtual Machine:
- Launch your Git application.
- Type
vagrant upto start the virtual machine. - Type
vagrant global-statusto check if the virtual machine is running. - Type
vagrant ssh-configto get the configuration of the virtual box for setting up remote access in VS Code. Copy and save this configuration to your notepad.
Installing the Remote-SSH Extension in VS Code:
- Open VS Code and click on the
Extensions tab. - Search for
Remote SSHin the extension search box and click Install.
Connecting to the Virtual Machine:
- Click on the
Remote SSH tab. - Click on the
+sign in the SSH options panel. - Enter a name of your choice in the new search box and press Enter.
- Select
C:\Users\<your-username>\.ssh\configand press Enter. - Select
Open Configfrom the pop-up message in the lower right-hand corner. - Copy and paste the configuration from your notepad into the new panel. (Remember to delete anything in the opened config file before pasting the configuration)
- Optionally, change the Hostname from the
defaultto your preferred name. - Close the panel containing the Host details.
- Click
Refreshon the control panel of Remote SSH.
- Click on
>to find your new SSH platform.
- Select and click on the arrow sign on your new SSH platform to connect.
- Select
Linuxfrom the pop-up search bar (since Ubuntu is a Linux distribution).
- Wait for the connection to be established.
- After connecting, click on the three dots in the upper bar of VS Code and select
Terminal. - Click on
New Terminalto open the terminal in VS Code.
You will notice that your VS Code terminal can now access your virtual machine terminal. Remember to always vagrant up your virtual machine using Git before opening VS Code after a shutdown or restart of your laptop or PC.

Top comments (2)
Cool, I'll try, I've always tried to use it on the iPad with vscode online but I always lost the connection when I took the focus out of vscode, I'm going to try this method, thank you very much and congratulations for the article.
Sure, you should try it out. Thank you