Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting Visual Studio Code (VSCode) to VirtualBox VM

I've been using WSL to debug C in VSCode, using Ubuntu from the Windows Store.

However, because my school projects must be able to run on a provided Virtual Machine (Lubuntu, in this case), it would be of great help if I could debug my code on Windows, through a connection to the Virtual Machine.

I've failed to find any good tutorials on this, so I tried playing around with the ip addr show command and connecting to the resulting address using ssh, but to no avail.

What would be the best approach to achieve this?

like image 789
cabralpinto Avatar asked Nov 15 '19 16:11

cabralpinto


People also ask

How do I connect visual codes to a VM?

This indicator tells you in which context VS Code is running (local or remote). Click on the indicator to bring up a list of Remote extension commands. Choose the Remote-SSH: Connect to Host command and connect to the host by entering connection information for your VM in the following format: user@hostname .

How does VS Code connect to remote server?

To connect to your remote machine, you can open this URL on any device. Note: You can also connect to your remote machine directly from vscode.dev: Open the Command Palette ( F1 ) in vscode.dev and run the command Remote Server: Connect to Remote.

Can I install Visual Studio in VirtualBox?

Double click the correct installer for your machine architecture, as shown in the image below. Follow the steps of the installer, and restart your machine when it is complete. When your machine has restarted, your Windows Virtual Machine is ready to use! You can now install Visual Studio and complete your projects.

How do I SSH into VirtualBox VM?

To open VirtualBox for SSH connections, we need to change the VirtualBox network settings to allow the SSH connection. Navigate to VirtualBox settings -> Network and make sure you have the settings Attached to NAT. Then go to Advanced -> Port Forwarding and add these settings: Name: ssh (or whatever you like)


1 Answers

Found the solution. In the VM settings, I needed to add a Network Host-only Adapter. From there, I installed openssh-server in my VM:

sudo apt-get install openssh-server openssh-client

Then, by calling ifconfig I got my VM's ip (enp0s8 interface) and connected to it via ssh.

Hopefully this helps anyone facing the same issue.

like image 147
cabralpinto Avatar answered Oct 11 '22 13:10

cabralpinto