VNC worked once only. Now "X server already running"

I installed & configured tigervnc as per [root tip] [How To] Install Raspberry Pi - VNC over SSH

Initially I chose display :4 and geometry of 1280x720. I created ssh tunnel and connected from my mac via the tigervnc client. It worked, but the screen was tiny, so I reconfigured the geometry and restarted the service. I then received connection failures.

In debugging this I have checked logs, done a full reboot and tried different displays. There’s always an “X server already running” on whatever display I choose and the connection is always refused.

(By the way, this box has no monitor so I only require X for the VNC connection)

This is my current config:

cat ~/.vnc/config
cat /etc/tigervnc/vncserver.users

And this is the vnc log:

Using desktop session xfce

New 'jem-manjaro:7 (jem)' desktop is jem-manjaro:7

Starting desktop session xfce

Xvnc TigerVNC 1.13.1 - built Aug 10 2023 01:23:35
Copyright (C) 1999-2022 TigerVNC Team and many others (see README.rst)
See for information on TigerVNC.
Underlying X server release 12101006

Thu Oct 12 12:24:42 2023
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5907
 vncext:      created VNC server for screen 0
[mi] mieq: warning: overriding existing handler (nil) with 0x562bec54e010 for event 2
[mi] mieq: warning: overriding existing handler (nil) with 0x562bec54e010 for event 3
xinit: XFree86_VT property unexpectedly has 0 items instead of 1
Running X session wrapper
Loading profile from /etc/profile
Loading profile from /home/jem/.profile
Loading xinit script /etc/X11/xinit/xinitrc.d/
Loading xinit script /etc/X11/xinit/xinitrc.d/
Loading xinit script /etc/X11/xinit/xinitrc.d/
X session wrapper complete, running session startxfce4
/usr/bin/startxfce4: X server already running on display :7
gpg-agent: a gpg-agent is already running - not starting a new one
xinit: connection to X server lost

waiting for X server to shut down
Thu Oct 12 12:24:43 2023
 ComparingUpdateTracker: 0 pixels in / 0 pixels out
 ComparingUpdateTracker: (1:-nan ratio)

The tunnel is created with ssh jem@$LOCAL_IP -L 9907:localhost:5907

The client connection string is localhost:9907

What’s going on, and how can I fix this reliably?

I think your issue is the chosen screen :7 try switching to screen :4 and restart your device.

The reasoning behind chosing screen :4 is founded in avoiding collision with window managers and des which defaults to use :0, :1 and :7. You can of course use an arbitrary number like :20 - all things considered - it is to avoid messages like this.

Another issue may occur if you logout of your remote session (as opposed to closing the remote view) as that will break your connection and you need to restart the service (either using ssh or by restarting the device).

  • changed back to :4 and restarted the device.
  • created tunnel ssh jem@LOCAL_IP -L 9904:localhost:5904
  • attempted to connect via localhost:9904

Connection is still refused. Note that this is the config that originally worked, but stopped working after I changed the geometry setting.

I then reverted geometry setting back to the original geometry=1280x720 and executed systemctl restart vncserver@:4, restarted the tunnel ssh jem@LOCAL_IP -L 9904:localhost:5904 - connection still refused.

I then chose the arbitrary display of :21 and tried again. Created tunnel 9921:localhost:5921. Attempted connection to localhost:9921. It was also refused.

Logs show /usr/bin/startxfce4: X server already running on display :21

This doesn’t seem to be related to the display id. No idea why it worked once but never again. Not sure if the X server already running is actually a problem or not.

I think you are forgetting something.

When using a guide as template there is usually a great amount of work put into ensuring the guide works if applied as a whole.

You have added alwaysshared to your config and removed localhost plus altering the remote screen to :7 thus creating a scenario which is not described in the guide.

I don’t know why you did choose :7 but I fair guess is - this is the default X-org server screen, which may explain why you get issues with the xorg server already running.

Connecting using SSH is creating a tunnel map using the schema localport:localhost:remoteport

When you change the remote screen you need to take this into account when you start the SSH connection.

The client-side port - in the example 9904 doesn’t have to change but the remote has
E.g. when chaning from :4 to : 21

The ssh connection changes

ssh ip.x.y.z -L localport:localhost:5921

But that is not enough - as you need to remove the old service on the target and create a new service uing the new screen number

systemctl disable --now vncserver@:4
systemctl enable vncserver@:21

Thanks for your help, and for the guide.

To wrap this up… I tried many approaches: making the config look exactly like the guide, disabling/enabling, creating a new user and configuring for it instead with reboots after each change. Nothing would fix it. Ultimately I removed and reinstalled tigervnc, and it worked again. It continues to work. I will not be trying to modify the geometry, but will use it as is.


I have - before I wrote my latest comment - tested the whole setup from scratch.

It failed for me when using the configuration you posted - I think it is important to know which options to use in the given context