Editing files in Linux VM using remote Visual Studio Code
Sometimes we need to edit a file directly on Linux VM using Visual Studio Code.
-
Launch Visual Studio Code. Additionally, you have to able to connect to the bash of remote machine from VS Code.
-
Go to the ‘Extensions’ page and search for ‘Remote VSCode’
-
Install the extension and re-launch Visual Studio Code ( client side of rmate)
-
In your Linux Virtual Machine, execute the following command in your terminal to install rmate server
mkdir /opt/rmate
$ sudo wget -O /opt/rmate/rmate https://raw.github.com/aurora/rmate/master/rmate
$ sudo chmod a+x /opt/rmate/rmate
ln -s /opt/rmate/rmate /usr/local/bin/rmate
- Go back to your Visual Studio Code and open up the command palette (CTRL+P for Windows and CMD+P for Mac) then execute the following command:
Remote: Start Server
- Once the server is ready, open up a new terminal and connect to your Linux Virtual Machine using the following command:
$ ssh -R 52698:localhost:52698 VIRTUAL_MACHINE_IP_ADDRESS
- In vs code terminal, execute the rmate command with the file that you want to open up in your Visual Studio Code in your local machine
$ rmate demo.py