Surya.dev
Published on

Connect Compute Engine - VM instances Google Cloud

Authors

Connecting to a Google Cloud VM instance is an important aspect of managing and utilizing cloud resources effectively. Whether you're a developer, systems administrator, or cloud enthusiast, understanding the various methods for connecting to your VM instances can simplify your workflow and increase your productivity. In this blog, i show to connect remote server google cloud - VM instance with VSCode.

Step 1 :

Install Extension remote ssh in vscode. Image instal extension

Step 2:

Generate SSH key pair. You can check this google docs here OR you can follow step this

#your home directory
$ ssh-keygen -t rsa -f ~/.ssh/mywebserver -C suryaharahap18@gmail.com -b 2048

Step 3:

Add public SSH key in VM instance - Google Cloud. You can follow this step by step

$ cd .ssh
$ cat mywebserver.pub #copy public key

Copy paste public key in VM instance

  • Select name instance Image select name instance
  • Edit VM instances

    Image edit vm instance
  • In Security and access, you can add item (number 1 in image) SSH keys and paste public key in this column (number 2 in image )

    Image In security and access

Step 4:

Configure SSH Hosts

in the keyboard (macOS) select CMD + shift + p > Remote-SSH: Connect to Host

Image select remote ssh to host

Select Configure SSH Hosts…

Image Configure SSH Hosts

Select /Users/surya/.ssh/config

select config

And following this config


Host ecs-user 
    HostName 8.219.41.49 #IP address from VM instance Google CLoud
    User root
    IdentityFile ~/.ssh/mywebserver #location file generate ssh keys

Step 5:

  • Connect to host by terminal

    ssh -i .ssh/mywebserver username_instance@35.198.223.99
    
  • Connect to host by VSCode editor

    In the keyboard (macOS) select CMD + shift + p > Remote-SSH: Connect to Host… and select you name server instance

    Image connect vscode
    Image finally success remote vscode

And now you can view vscode connect remote server VM instance - Google Cloud 🙌🏻