SSH into Remote VM with VS Code | Tunneling into any cloud | GCP Demo

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi and welcome back everyone me Robert here some of you guys watching my videos asked me how I managed to open a remote folder in Visual Studio code via SSH and that's exactly what I'm going to show you in this video with this approach you can use your Visual Studio code on your local machine but store and run your applications on a remote machine in the cloud this is especially useful if you want to build resource intensive applications like AI tools with large language models what we will do in the next videos today I will show you an approach for tunneling into literally any remote machine on any cloud provider however I will demonstrate this live by creating a virtual machine in the Google Cloud so if you think that sounds interesting hit the Subscribe button and the notification Bell below so you can keep up to date with all of our videos so without further Ado let's get to it all right let's create a virtual machine in the Google Cloud if this is the first time you interact with the Google Cloud then you have to create a project and to enter your payment details within this project you can create a new virtual machine instance for this demo I name this virtual machine instance remote SSH demo and here in the region section you can choose a region that is closest to your location since I'm located in Europe I choose a European location here and also a European Zone here you can choose a machine configuration that fits your use case you can choose between general purpose compute optimized memory optimized or gpus this prefills the CPU platform and the Machine type which you can change to your needs then you scroll down to the boot disk section here you can change the size of your boot disk and you also can choose your operating system I'm fine with the Debian Linux so I scroll down and click create here I can see that my virtual machine instance is running and I could SSH into it right here but I don't do this since I want to SSH into this virtual machine through Visual Studio code so I switched to visual studio code and click on the extensions tab here here you can see that I've installed the remote SSH extension from Microsoft if you haven't installed it yet then you can search it in the marketplace here by entering remote SSH and then you click on it then you click on the install button here and wait until the extension is installed in order to configure your connection to the virtual machine you click on view and command palette you could also press F1 which brings up the same screen to then you enter remote SSH here and you choose open SSH configuration file this allows you to choose a config file in your home directory in the dot SSH folder if you do this for the first time then this file is pre-filled with some dummy information here in the host line you can enter an alias name for your host you are free to choose any name here you like I enter remote SSH demo here and here in the host name line you enter the IP address of your virtual machine for this purpose we switch back to our virtual machine and we click on it then we scroll down to the network section and we find the external IP address here we copy it then we switch back to visual studio code and we enter the IP address in the hostname section here let me zoom in here a little bit so that you can see it better here in the user section you enter the name the username with which you want to SSH into this virtual machine but one important part is missing the section for the identity file which holds the private key therefore we create a new line identity file and here we have to specify the path to a private key since we have no private key yet we open the terminal and we create a directory where we want to store our keys we change into this directory and now we can create a private public key pair with this command SSH keychain followed by the algorithm which we want to use to generate the keys in our case this is RSA here we provide the file name and the path where we want to store the private key and here we specify our username and here we specify the key size in bits then we click enter here you can enter a passphrase or leave it empty we leave it empty and here the keys are generated we list the content of the directory here we can see two files the first file contains the private key and the second file with the dot Pub extension contains the public key now we enter the path to the private key here in this identity file section in our config file like so and then we open the public file here in the editor and we copy the content of this public file and now we switch back to our virtual machine here we click on edit to edit the virtual machine then we scroll down to the SSH section here SSH keys and here we click on add item and here we paste our public key that we previously created on our local machine then we click save now we switch back to visual studio code we close the public key file and we save the SSH config file now we can connect to our Virtual Machine by hitting F1 and entering remote SSH connects to host then we choose remote SSH demo our virtual machine host name here and this opens a connection to a remote machine and here we choose our operating system which is Linux and here on the left bottom of this window we can see that an SSH connection to our remote SSH demo virtual machine has been established successfully we maximize the screen here and now we can open a folder here on the remote machine like on our local machine here we trust the authors here on the left side you now can see the directories and files in our home directory of our remote machine and we also can open a terminal window on our remote machine here if you're interested to see where on this remote machine your public Keys have been stored you can open the dot SSH directory here dot sh directory and open the authorized Keys file finally if you do not want to connect to a virtual machine on the Google Cloud platform and you're not sure if the SSH server is running on your remote machine then you can enter this command which gives you the status of the SSH server and if it's not running then you can install the SSH server with this command that's all for today if you like this content please subscribe to my channel and thank you for watching
Info
Channel: Blue Antoinette
Views: 21,314
Rating: undefined out of 5
Keywords: SSH, VS Code, remote machine
Id: 0Bjx3Ra8PRM
Channel Id: undefined
Length: 10min 25sec (625 seconds)
Published: Fri May 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.