Getting a Gnome desktop in VNC under Ubuntu

There is a lot of old and wrong data out on the net about this. I think it is because of the continuing evolution of the desktop environment/gnome/unity etc., most of which I don’t understand.

Below is the overall approach I use, and some things I had to do to make it work. I will use as an example getting up a vnc viewer screen on oregano showing a gnome desktop on cinnamon. Interestingly, it proved much harder on cinnamon (running Wily Werewolf) than on pepper or the Butcher box named kodi, both of which are running Trusty Tahr.

On oregano the file /usr/local/bin/<remote hostname> contains a script to make an ssh connection to <remote hostname> and also to establish various ssh tunnels to that hostname (for example, to look at databases). In the case of hosts where I want to be able to open a graphical environment using vnc, the script will contain the following, among other things (here the remote host is cinnamon, and the port numbers in the command aren’t important, except that the “:3” has to match the “5903”. Selecting the port numbers carefully beccomes important if one has multiple such connections in play at once):

ssh uname@cinnamon vncserver -geometry 2400x1200 :3
ssh -L *:5901:localhost:5903 -g uname@cinnamon

which runs the vncserver command on cinnamon as user uname. The vncserver command looks for an xstartup file under ~/.vnc/xstartup. That file is the key. The (important) contents of the file are (line folding is not in the file):

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
gnome-session --disable-acceleration-check –session=gnome-flashback &

I think that the parameter –disable-acceleration-check is still required, as of this writing, but it is one thing I put in to try to solve the problem, and then had to do other things, and I haven’t yet gone back to test without it. In any case I’m pretty sure it can’t hurt, because acceleration is what we don’t have. (Update: I later found pepper didn’t work correctly till I put it in).

Incidentally, in debugging all this, I found it very useful to add –debug to the parameter line for gnome-session. The log created by gnome-session goes into the .vnc directory and has a lot of poodah.

Over the years the contents of the “–session=” parameter have changed. The main difficulty (as I understand it) is that since this will be run through the ssh pipe to a vnc screen, we cannot use a desktop manager which requires 3d acceleration hardware. However the “session=” parameter must correspond to a “session” file which has to exist in one of a set of possible places successively searched:

/usr/share (the final, and default).

In each directory what is sought is ./gnome-session/sessions/<session file>. Most of the old stuff on the web refers to session files (like ubuntu-2d) that don’t exist anymore.

As of now the session file that works is called gnome-flashback (it was formerly called gnome-fallback). It does not come standard with ubuntu anymore (at least on Wily). I found that it was present on Trusty on both pepper and kodi). Install it with:

apt-get install gnome-session-flashback

This installs /usr/share/gnome-session/sessions/gnome-flashback-compiz.session and /usr/share/gnome-session/sessions/gnome-flashback-metacity.session. On Trusty, I found that gnome-session/sessions contained gnome-flashback-compiz.session and also gnome-flashback.session. Eventually I decided that I could just copy the one from Trusty, and use it on Wily. One can create their own version of this file pretty easily, and store it in ~/.config/gnome-session/sessions.

In ~/.config/gnome-session/sessions/gnome-flashback.session (line folding not in the file):

[GNOME Session]
Name=GNOME Flashback (Metacity)

The components named (like gnome-panel) are each the name of an “application” that exist as a “.desktop” file (e.g. gnome-panel.desktop), also in one of a sequence of possible locations:


So the first hurdle is to have the xstartup file specify a session file that actually exists in gnome-session/sessions/*, and it has to be one that does not require 3d acceleration.

The next hurdle, for me (in Wily), was in the gnome-panel.desktop file, started by the session file. The gnome-panel “application” is (I think) not used by the more modern gnome sessions – it was loaded (into /usr/share/applications) by the install of gnome-session-flashback. But the gnome-panel.desktop file loaded by the install contains a line:


The trick here is that the name specified in OnlyShowIn has to match the “DesktopName” in the session file. There is not a “DesktopName” in either the gnome-flashback-compiz.session or the gnome-flashback-metacity.session files that got loaded on Wily, and so the gnome panel kept getting loaded on Wily even when I was logging into the ordinary Unity desktop. I needed to ensure that the OnlyShowIn= line in the desktop file matched the DesktopName= name in the session file. When I started using my own session file (as typed above), it worked.

On cinnamon I have installed the session file and the desktop file in ~/.config which will be preserved across reinstalls since my home directory persists.