1 minute read

I recently started using cloud VMs for some personal projects. Initially I accessed the VMs through the cloud shells (azure, gcp) for quicker access. It works great and has tonnes of features too, but I miss the familiarity of local development which I used to get with VS Code.

VS Code’s remote ssh extension makes it much easier to develop with remote servers, making the remote development very much like native development. The steps I used to set up my remote development environment with a Linux VM on GCP and work with VS Code on macOS.

  • Generate the ssh keys on the local machine
# This will generate private and public key file at the given path.
# Replace <key-file> with the name of the key and <gcp-user-name> with your GCP user name
$ ssh-keygen -t rsa -f $HOME/.ssh/<key-file> -C <gcp-user-name>
  • Create a VM, and add instance level public keys. The contents of the public key generated in the above step will have to pasted in the SSH keys section
  • VM can then be accessed using the external IP assigned to it. (e.g. ssh user@35.229.100.113 -i $HOME/.ssh/my-gcp-key)
  • Update SSH config file on the local machine for easy access.
Host my-gcp-vm
    HostName <VM-External-IP>
    User <GCP-user-name>
    IdentityFile <path-to-key-file>

Moving from GCP to Azure VM

The external IP assigned to GCP VM is ephemeral, so we get a new external IP upon restarting the VM. The SSH config file will then have to be updated every time the external IP is changed. I tried to get a FQDN for the GCP VM, but later realized that it is not supported out of the box. This article setting up a custom host name for GCP VM.

Interestingly, Azure supports FQDN out of the box without having to set up our own DNS record. The fqdn subdomain may vary depending on the location. My VM was deployed in the US East Zone, so I had something like this <vm-name>.eastus.cloudapp.azure.com.

With Azure Virtual Machines extension and FQDN assigned to the Azure VM, I could control start/stop of the VM and access the VM through SSH all within VS Code without stepping out. That makes the workflow with Azure VMs much easier than GCP VMs.

Comments