Connect a VM with VS Code for Remote Development

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 V…


This content originally appeared on DEV Community and was authored by Godfrey Nyarko

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:

  1. Launch your Git application.
  2. Type vagrant up to start the virtual machine.
  3. Type vagrant global-status to check if the virtual machine is running.
  4. Type vagrant ssh-config to 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:

  1. Open VS Code and click on the Extensions tab.
  2. Search for Remote SSH in the extension search box and click Install.

Installing Remote SSH

Connecting to the Virtual Machine:

  1. Click on the Remote SSH tab.
  2. Click on the + sign in the SSH options panel.
  3. Enter a name of your choice in the new search box and press Enter.
  4. Select C:\Users\<your-username>\.ssh\config and press Enter.
  5. Select Open Config from the pop-up message in the lower right-hand corner.
  6. 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)
  7. Optionally, change the Hostname from the default to your preferred name.
  8. Close the panel containing the Host details. Configuring VM
  9. Click Refresh on the control panel of Remote SSH. Refresh Remote SSH Panel
  10. Click on > to find your new SSH platform. Accessing VM
  11. Select and click on the arrow sign on your new SSH platform to connect.
  12. Select Linux from the pop-up search bar (since Ubuntu is a Linux distribution). Opening VM
  13. Wait for the connection to be established.
  14. After connecting, click on the three dots in the upper bar of VS Code and select Terminal.
  15. Click on New Terminal to 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.


This content originally appeared on DEV Community and was authored by Godfrey Nyarko


Print Share Comment Cite Upload Translate Updates
APA

Godfrey Nyarko | Sciencx (2024-06-27T06:31:55+00:00) Connect a VM with VS Code for Remote Development. Retrieved from https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/

MLA
" » Connect a VM with VS Code for Remote Development." Godfrey Nyarko | Sciencx - Thursday June 27, 2024, https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/
HARVARD
Godfrey Nyarko | Sciencx Thursday June 27, 2024 » Connect a VM with VS Code for Remote Development., viewed ,<https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/>
VANCOUVER
Godfrey Nyarko | Sciencx - » Connect a VM with VS Code for Remote Development. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/
CHICAGO
" » Connect a VM with VS Code for Remote Development." Godfrey Nyarko | Sciencx - Accessed . https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/
IEEE
" » Connect a VM with VS Code for Remote Development." Godfrey Nyarko | Sciencx [Online]. Available: https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/. [Accessed: ]
rf:citation
» Connect a VM with VS Code for Remote Development | Godfrey Nyarko | Sciencx | https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.