How to connect through VNC to Ubuntu on Azure

Connecting to an Ubuntu Server using VNC. Note*:



  1. If you haven’t done it from the portal, you can use the Azure CLI to deploy an Ubuntu Server 16.04. You will need to run this command from a terminal that has SSH installed and your SSH keys already generated because it will try to obtain ~/.ssh/ Also, the username you have in your terminal will give you access to the VM.

     az group create --name tests --location southcentralus
     az vm create -g tests -n bubulubuntu --image canonical:ubuntuserver:16.04-LTS:16.04.201612210

    Be patient, the creation of the VM could take some minutes. After it’s done you will obtain a public IP that you can use to SSH into your VM ssh <<VM PUBLIC IP>>

  • Inside of the VM you should be seeing this output.

      Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-57-generic x86_64)
      * Documentation:
      * Management:
      * Support:
      Get cloud support with Ubuntu Advantage Cloud Guest:

      0 packages can be updated.
      0 updates are security updates.
      Last login: Wed Dec 21 21:49:06 2016 from
      To run a command as administrator (user "root"), use "sudo <command>".
      See "man sudo_root" for details.

    Lets start by installing TaskSel, which will manage the installation of the Desktop Environment.

      sudo apt-get update
      sudo apt-get upgrade
      sudo apt install tasksel
  1. Run tasksel and install Ubuntu Desktop

     sudo tasksel

    alt text

    Here you should put the cursor on the package “Ubuntu Desktop” and press space in your keyboard to mark it for installation, then press tab to go to <Ok> and finally enter to start the installation.

    alt text

  2. While this is installing in your server install a VNC client like VNC Viewer from RealVNC

  1. Back to your Ubuntu 16.04 server in the cloud, when the installation is done, install the Vnc Server you have to reboot the VM.

     sudo apt-get install vnc4server
     sudo shutdown -r now

    In your terminal you would see something like this:

     Connection to closed by remote host.
     Connection to closed.

    Give it a couple of minutes before trying to going back in again.

  2. SSH back into your Linux box and configure vncserver, don’t forget the password you choose (only 8 chars)

  3. Edit xstartup. First lets stop the server

     vncserver -kill :1

    And edit ~/.vnc/xstartup so it looks like this:

     # Uncomment the following two lines for normal desktop:
     exec sh /etc/X11/xinit/xinitrc
     [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
     [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
     xsetroot -solid grey
     vncconfig -iconic &
     x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
     x-window-manager &

    And now restart the vncserver

  4. Make a tunnel

     ssh -L 5901: -N -f -l
  5. Open VNC viewer and connect to localhost:5901