2

I believe, this post could be useful for community as a guide what to expect from TigerVNC and Ubuntu. If there is a better place, or better format - please suggest where to put it. There are few small tricks, which make things working, but which are not readily available in the Internet. Anyway, if this piece of information is not valuable for community and is not seen by community I am Okay to delete this post.

I'll appreciate if someone authorized would advise how to proceed better.

I would like to share some chronicles about my fight with Ubuntu Bionic Turtle 20.04.1 and with latest TigerVNC server. It seems all of the guides in the Internet are simply outdated and do not catch current situation with tool and OS. This will become evident very soon. So, let me begin.

Install all necessary packages

# apt install tigervnc-standalone-server tigervnc-common tigervnc-xorg-extension tigervnc-viewer

Change active user and setup VNC password

# su - user
$ vncpasswd

At this point almost all guides are suggesting to run

$ vncserver -localhost

to get necessary configuration files in ~/.vnc directory. I have to upset their authors - this is no longer working. vncserver -localhost does nothing and terminates with error. During installation TigerVNC creates a specific file at /etc/X11/Xvnc-session, which is some sort of proxy for system-wide Xsession file under the same hierarchy. By default, TigerVNC is sourcing this file and ignores whatsoever local ~/.vnc/xstartup. There are two critical files in ~/.vnc/ hierarchy, I will speak about this further.

Apparently, there is no way to run TigerVNC from command line shell - it is no longer supported. Only service is necessary. As documentation states, it is not possible to create correct environment form command line, the only thing which is possible to get from command line is black/teal/gray screen with cross cursor in the best case.

So, I decided to configure service. There are many examples of service file configurations. /etc/systemd/system/vncserver@.service file:

[Unit] 
Description=Remote desktop service (VNC) 
After=syslog.target network.target

[Service] Type=forked User=user PAMName=login PIDFile=/home/user/.vnc/%H%i.pid ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || : ExecStart=/usr/bin/vncserver :%i -localhost no -geometry 1024x768 -depth 24 ExecStop=/usr/bin/vncserver -kill :%i

[Install] WantedBy=multi-user.target

After

$ sudo systemctl daemon-reload
$ sudo systemctl enable vncserver@1
$ sudo systemctl start vncserver@1
$ sudo systemctl status vncserver@1

TigerVNC complains about abnormal termination of /etc/X11/Xvnc-session initialization script and does nothing. This is the place, where ~/.vnc/config becomes necessary. It may contain many options, but the critical one in my case is

session=ubuntu

Apparently, it is possible to specify any session, list of available sessions could be found at /usr/share/xsessions. As documentation states, there are files like

ubuntu.desktop
xsession1.desktop
xsession2.desktop

Variable session must be equal to name of the session without extension, i.e., ubuntu, or xsession1, or xsession2. After creating this local config file I was able to run TigerVNC for configured user account, but what a surprise, session become inactive immediately after started, again with some error. Further investigation reveal additional arguments, which has to be added to service configuration file:

Environment=XDG_SESSION_TYPE=x11

It took a lot of time to figure this out. It is necessary to use loginctl to find out what session type needs to be specified for XDG_SESSION_TYPE. Per my investigation, correct values are "x11" and "wayland". I don't know what is "wayland" and how it is different from "x11". For my case "x11" was correct setting. After this setting VNC session for selected user become almost operational.

$ sudo systemctl start vncserver@1
$ sudo systemctl status vncserver@1
$ sudo systemctl status vncserver@1

If one is fast enough, first status call displays operational TigerVNC service, while second one displays TigerVNC service as terminated with zero exit code. No error, session just terminated. That took me few hours of debug. After checking few hundred lines from /var/log/syslog I found many services complaining about some strange errors and later Xserver exits because of some critical process for it gets terminated. Few hours of search revealed a very dirty hack - it is necessary to change /etc/systemd/system/vncserver@.service file the following way:

[Unit] 
Description=Remote desktop service (VNC) 
After=syslog.target network.target

[Service] Type=simple User=user Environment=XDG_SESSION_TYPE=x11 PAMName=login PIDFile=/home/user/.vnc/%H%i.pid ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || : ExecStart=/usr/bin/vncserver :%i -fg -localhost no -geometry 1024x768 -depth 24 ExecStop=/usr/bin/vncserver -kill :%i

[Install] WantedBy=multi-user.target

As a result, service is run in context of systemd and X applications are able to get all necessary handles from system/environment. At this point I was able to see my desktop in vncviewer from my MacOS computer. BTW, user account, for which TigerVNC is run is no longer accessible from console. Any login attempt is terminated immediately after password is input.

I remember myself setting up VNC server just few years ago for CentOS 5/6/7 and Ubuntu 14/15/16, Debian 10 and several other OSes. I never before had even 1/10th of issues I got with installation of TigerVNC for Ubuntu 20.04.1. Always before installation was smooth and simple. Now I have a few really big questions to people here:

  1. Is this is a normal situation?
  2. Do I just see a major changes in Ubuntu/TigerVNC, or this is new way things are going to work from now on?
  3. Why did they block local and remote desktops co-existence? Now I need to have separate accounts for local and remote work, which is really painful.
  4. Do I have any serious errors with my way of setting up things and is it possible to stream-line things and make them simple?

0 Answers0