7

I am a very basic user in Google Cloud Platform.

Is it possible to use a GUI of my VM instance ? I am currently using Centos7 VM.

codingfreak
  • 4,467
  • 11
  • 48
  • 60

2 Answers2

5

You can use VNC to connect to VMs on Google Compute Engine. Here's a detailed tutorial for how to set this up.

For added security:

  1. use a long, complex password (though note that VNC limits passwords to 8 characters)
  2. instead of opening up port 5901 to the Internet, consider using an SSH tunnel. This is more complex, and depending on your Internet connection, may slow down your graphics refresh rate, but will be more secure.

To use the alternative approach with an SSH tunnel, here are the differences from the tutorial you need to follow:

  1. don't open port 5901 in the Google Compute Engine firewall
  2. create an SSH tunnel from your desktop/laptop to GCE VM via:

    gcloud compute ssh \
        ${VM_INSTANCE} \
        --project $PROJECT \
        --zone $ZONE \
        --ssh-arg "-L ${LOCAL_PORT}:localhost:5901"
    

    where you need to provide the right parameters for ${VM_INSTANCE}, $PROJECT, and $ZONE that match your configuration. You can choose ${LOCAL_PORT} to be 5901 if you wish, but if you decide to VNC into several different GCE VM instances, you'll have to choose unique ports for your local machine.

    You need to keep this connection open to use VNC. If this connection is closed, you will lose VNC access as well.

  3. Instead of connecting to your VM using its external IP, connect via localhost:${LOCAL_PORT} with ${LOCAL_PORT} same as selected earlier in step #2

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
  • I followed the steps in the article and when I am trying the command $ nc localhost 5901 it fails saying "Connection refused". What is the username to my vm instance running in GCE ? – codingfreak Jul 10 '15 at 06:42
  • You need to run the command `nc localhost 5901` from the GCE VM, not from your local machine, that's why it's failing. To connect to your VM, use the same command as in my answer but without the `--ssh-arg` flag: [`gcloud compute ssh $VM --project $PROJECT --zone $ZONE`](https://cloud.google.com/sdk/gcloud/reference/compute/ssh). It will use the same username as on your local machine. It works by using [ssh keys](http://stackoverflow.com/a/27536795/3618671) which `gcloud` will automatically transfer to the instance for you. There is no default username / password for new GCE VMs. – Misha Brukman Jul 10 '15 at 13:41
  • I followed this guide but i only get X without any program nor mous click reactions. How to get gnome? ^^ – Phoenix Sep 15 '16 at 13:40
  • @Phoenix — please see https://wiki.centos.org/HowTos/VNC-Server if you are using CentOS; you may need to adapt the installation for other distributions, and update `$HOME/.vnc/xstartup` appropriately to run `gnome-session`. – Misha Brukman Sep 16 '16 at 15:25
1

My need was to connect a Windows TightVNC client to Google Compute Engine Cloud Instance of Debian 10 (Buster). The various tutorials I have worked through omitted one important step: make sure the vnc server is not restricted to localhost.

The essential steps for Google Cloud are summarized as

  1. confirm you have a running VM instance and that you have ssh access. I explicitly disabled enable-oslogin (how to disable oslogin) and loaded my own Puttygen-created SSH certificate.

  2. in VPC Networks > Network Interface Details > Firewall and routes > Rules add a rule to allow ingress for ip range 0.0.0.0/0 (or a known limited range), for tcp:5900-5920 (this allows for up to 20 VNC instances)

  3. set up the VNC server (tutorials here and for debian 9 here and for debian 10 here and more complete and recent here for debian 10

  4. after doing this, I could not get past "Connection refused." Missing step: make sure -localhost no is included as argument when starting the vncserver:

vncserver -localhost no

Once all these conditions were satisfied, I had desktop access.

wistlo
  • 250
  • 3
  • 11