VM GUI Setup - eecse4750/e4750_2024Fall_students_repo GitHub Wiki

Installing a GUI on the headless VM

It might prove useful to install a GUI on your VM so that you aren't restricted to the Command-Line-Interface. This tutorial will show you how to do so for your VM instance on Google Cloud.

Step-0: Install VNC Viewer on your local computer

You will need VNC Viewer to remotely view the desktop of your VM once you install a GUI. Download the viewed from the link given and install it to your local computer.

Step-1: Connect to your VM Instance

Follow the steps listed here to install gcloud cli: https://cloud.google.com/sdk/docs/install

After that you can follow the steps below:

Open your terminal/command line and connect to your VM using gcloud compute

$ gcloud compute ssh <UNI>@<vm-image-name>

If you have been using the browser SSH method of connecting to the VM, your username will be your UNI. If you have been using gcloud compute, then you may already know the right username to enter above in the place of <UNI>.

Step-2: Install GNOME and other necessary packages

$ sudo apt install gnome-shell ubuntu-gnome-desktop autocutsel gnome-core gnome-panel gnome-themes-standard

Once this is done, install VNC Server.

$ sudo apt install tightvncserver

Step-3: Setup VNC Server on the VM

a. Next, create a configuration file for the native X server by running:

$ touch ~/.Xresources

b. Run an instance of vncserver through the command line:

$ tightvncserver

c. You may be asked to set a password. You can choose to not set one. If you do, this password will be required when you use VNC Viewer to access the VM from the client side i.e. on your computer.

d. Next, you have to modify the startup script for VNC. Use vim (or nano) to edit it:

$ nano ~/.vnc/xstartup

e. Remove the file’s contents and replace everything with the following lines:

#!/bin/sh
autocutsel -fork
xrdb $HOME/.Xresources
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:Unity"
export XDG_MENU_PREFIX="gnome-flashback-"
unset DBUS_SESSION_BUS_ADDRESS
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check --debug &

f. Change the permissions of the file:

$ chmod +x ~/.vnc/xstartup

g. With this last step, you have successfully completed setting up VNC Server on the VM. Kill the current vnc server instance by running

$ vncserver -kill :1

h. Last, reboot your VM instance as a precaution

$ sudo reboot

Step-4: Connect to a running VNC Server through the Client

Note: You can use Step-4 everytime you need to access the GUI of your VM through VNC.

Start a VNC server with a defined display geometry by issuing the following command on the VM:

$ vncserver -geometry 1366x768

Now, close your connection to the VM. Simply close the terminal window or type

$ exit

Now you will connect to the VM again, but with a modified command. Open your terminal/command line on your local computer and use gcloud compute to connect in the following way:

$ gcloud compute ssh <UNI>@<instance-name> --ssh-flag "-L 5901:localhost:5901"

Recall that you installed VNC Viewer on your own computer in Step-0. Open VNC Viewer on your computer, and enter

localhost::5901

in the top bar as shown below:

localhost::5901

You may get an unencrypted connection warning. You may ignore it.

Next, you may be prompted for a password. If you set a password in Step-3(c), enter that here. If you didn't set one, just proceed ahead. You will finally see your GNOME desktop.

⚠️ **GitHub.com Fallback** ⚠️