Set up Ubuntu 16.04 with xfce and VNC server

I was installing vCenter on my ESXi server.  Since this was my first time installing vCenter, I decided that installing via UI was a far better choice than install from the CLI.  But then that meant I needed to get a UI on to the Ubuntu VM I had stood up to do the install from.  So this is what I did.

  1. Install the xfce4 and tightvnc packages.  Xfce is a desktop environment for Unix and Unix-like OS’s.  We will use Xfce, but you could use a different desktop environment if you want.
    sudo apt install xfce4 xfce4-goodies tightvncserver
  2. Validate that the server can be started and create an access password for view and control (you can also setup a separate password for view only)
  3. Configure vncserver to always use Xfce
    The configurations for vncserver are kept in the ~/.vnc/xstartup file.  Out of the box, it looks like this:

    xrdb $HOME/.Xresources
    xsetroot -solid grey
    #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    #x-window-manager &
    # Fix to make GNOME work

    We need to change this so it uses Xfce instead of GNOME.  You could edit the xstartup file directly (not recommended) or make a back up of it and start fresh with:

    xrdb $HOME/.Xresources
    startxfce4 &
  4. Make the startup script executable
    sudo chmod +x ~/.vnc/xstartup
  5. Start VNC server
  6. Test from a Mac OS X machine.
    1. Open an ssh session with port forwarding
      ssh -L 5901: -N -f -l username server_ip_address
    2. Open Screen Sharing
      1. From Safari or from Spotlight, type:
    3. You should see something like this:
  7. Daemonize the VNC Server
    1. Create the service
      sudo vi /etc/systemd/system/vncserver@.service

      Add the following to it.  Replace $user with your username

      Description=Start TightVNC server at startup
      ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
      ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
      ExecStop=/usr/bin/vncserver -kill :%i
    2. Register the service with the system
      sudo systemctl daemon-reload
      sudo systemctl enable vncserver@1.service
    3. Kill any currently running instances
      vncserver -kill :1
    4. Start the service
      sudo systemctl start vncserver@1

Leave a Reply

Your email address will not be published. Required fields are marked *