15

I spent a couple of evenings on this, and it's getting a bit frustrating since I managed to had it working on my previous Ubuntu (MANY years ago).

I'd like to have an vnc server running on my server at any time (including login screen) to remotely connect and login. Not a different session: share the same session I would see on the physical display of my server and log on to it remotely via VNC in a private network (aka home).

I understand it's a combination of XDMCP, GDM3, initd and VNC configurations, but I don't have enough experience to tune the various howtos I found online to work for ubuntu 18.04.

These seems promising links: https://lists.debian.org/debian-user/2017/04/msg00529.html https://codeghar.wordpress.com/2009/06/11/remote-login-with-gdm-and-vnc-on-fedora-11/ https://wiki.openindiana.org/oi/4.7+Remote+Graphical+Login:+Using+Xvnc+and+gdm+for+One-Shot+sessions

Right now (in case anyone else is going crazy like me), I installed nomachine and it took the grand total of 2 minutes to setup and it works as I wanted (including iOS clients!): https://www.nomachine.com/ ---bittersweet ¯_(ツ)_/¯

4
  • Need to bind x11vnc to screen instead of session.
    – Seb
    Jun 6 '18 at 8:51
  • 3
    Thank you for the NoMachine rec. After a weekend of installing x11vnc, tightvnc, tigervnc, vnc4server and more and nothing working with 18.04 and gdm3, I finally gave up and used NoMachine, worked perfectly. Pretty disappointed in 18.04 LTS right now though.
    – jb510
    Aug 12 '18 at 18:09
  • I went the same path: frustrating evenings trying to get various vnc solutions working but to no avail. Installed nomachine and it works (though not in 2 minutes due to: nomachine.com/AR03P00973). Anyway: now that I see the solution below (switching to lightdm), I wonder: did you try it? Is it worth switching from nomachine to this more open source solution?
    – Christoph
    Feb 3 '19 at 23:30
  • I tested @seb solution with Debian 10 with Mate and it worked.
    – S.V.
    Aug 23 '20 at 2:08
18

Ubuntu 18.04 switched from LightDM to GDM3. Connecting to the login screen with VNC while using GDM3 is currently not possible. The easiest way to get this VNC functionality back is to simply switch back from GDM3 to LightDM.

LightDM is still being actively developed and used by many Linux distributions including some other flavors of Ubuntu. So no worries there.

Install LightDM

apt install lightdm

Should you for some reason come to regret switching to LightDM:

dpkg-reconfigure gdm3

Once you have LightDM installed and configured as your default greeter..

Install x11vnc from packages

apt install x11vnc

Create the file /etc/systemd/system/x11vnc.service

# Description: Custom Service Unit file
# File: /etc/systemd/system/x11vnc.service
[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service

[Service]
ExecStart=/usr/bin/x11vnc -loop -nopw -xkb -repeat -noxrecord -noxfixes -noxdamage -forever -rfbport 5900 -display :0 -auth guess
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

Enable the x11vnc service

 systemctl enable x11vnc.service

This assumes screen :0 represents your monitor and binds x11vnc to that monitor instead of a session. If you do not have a monitor (headless) you can install the xserver-xorg-video-dummy package and use the dummy driver to configure a virtual :0 screen for you.

Side notes

  1. Incase you are using virt-manager (which also enables VNC on 127.0.0.1:5900) you may want to bind x11vnc to your LAN IP (-listen 10.0.0.1)
  2. The parameters used to start x11vnc tell it not to ask for an additional password (-nopw)
8
  • 1
    To start vnc session x11vnc -display :0 It can only connect to one session, once your session is expired or closed, you will have to start again with x11vnc -display :0
    – ashish
    Aug 30 '18 at 5:58
  • "Restart-sec" should be "RestartSec"
    – eakst7
    Dec 31 '18 at 13:15
  • 1
    When you say "fake monitor" for headless, do you mean xserver-xorg-video-dummy?
    – Christoph
    Feb 3 '19 at 23:34
  • As a note: never create your own config files in /lib, use /etc: /etc/systemd/system Mar 13 '20 at 11:40
  • Modified to include suggested changes from comments.
    – Seb
    Apr 23 '20 at 14:48
1

I have not yet found a nicer way, but if you really want to login it looks like it is possible.

GDM starts one Xsession for the login screen owned by the root user. As far as I can tell it will perform logins approximately this way:

Login, find existing session and switch vt to it or find a new vt and run an Xorg/gnome-session for it.

The first has display :0 and its authority file (gdm user id 121) /run/user/121/gdm/Xauthority. So you can first run a x11vnc (root rights) if you are not logged in for the DM itself and login (your x11vnc will turn black due to the vt switch). You can either start a new x11vnc manually for your new display :1 (no root rights) or start one automatically with your session as any other logon script.

~$ ps -a | grep Xorg
1471 /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/121/gdm/Xauthority -background none -noreset -keeptty -verbose 3
5337 /usr/lib/xorg/Xorg vt3 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3
/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 

This has been decided at some point (other DMs might do the same in the future)

1
  • Indeed. VNC can't switch session/screens like GDM does and one would hafto manually reconnect to the freshly spawned VNC bound to the new session. I once considered writing a proxy for it in python that would switch automatically but never got around to it, specially since I'm not bothered by the switch to LightDM.
    – Seb
    Nov 13 '20 at 21:16
1

Ritualmaster is right in their answer: it's possible to login remotely through GDM3 with x11vnc.

  1. You have to install x11vnc.

    sudo apt install x11vnc
    
  2. You should create a password

    x11vnc -storepasswd /path/to/passfile
    
  3. If not provided, default location is ~/.vnc/passwd

    x11vnc -storepasswd
    
  4. You'll need to list the Xsessions

    ps aux | grep auth
    

The first line is the Gnome Desktop Manager login screen.

root  /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/124/gdm/Xauthority -background none -noreset -keeptty -verbose 3
fho   grep Xorg
  1. Provide the proper authority and set the display to :0

     sudo x11vnc -display :0 -auth /run/user/124/gdm/Xauthority -rfbauth ~/.vnc/passwd
    

If you connect to it, you'll see the login screen. As soon as you log in, the screen will become black. The server should shut down automatically.

  1. Find the user session screen

     ps aux | grep Xorg
    
root  /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/124/gdm/Xauthority -background none -noreset -keeptty -verbose 3
root  /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3
fho   grep Xorg

The second line is the one you're looking for. You can now start again the x11vnc server by replacing the display number and the user session Xauthority

   x11vnc -display :1 -auth /run/user/1000/gdm/Xauthority  -rfbauth ~/.vnc/passwd
0

Another way of making this work on 100% headless setup (system running inside container and doesn't have any GPU at all) is "On demand multi-user mode" part of TigerVNC article in ArchWiki.

0

After testing many many solutions/scripts for vnc, this xtartup file works well for me on ubuntu 18.04 Lts with tiger vnc :

#!/bin/sh
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

And this launch command :

vncserver -localhost no -geometry 1024x768 -depth 24

Taken from this tutorial :

1
  • I just end up at the normal (broken) GDM3 login screen, even after setting up this as the ~/.vnc/xstartup script... :/ btw the second link is now dead.
    – BjornW
    Nov 12 '20 at 17:02
0

I am on Ubuntu Server 18.04.4, with ubuntu-desktop installed from tasksel, so i don't really know if this will work with regular out-of-the-box Ubuntu Desktop or if this is a 'going-to-be-obsolete' option.

After trying some 3rd party VNC servers, i ended up with the built in vino-server (Screen Sharing). To run it you need to do~$ /usr/lib/vino/vino-server which then will listen on port 5900, and as this is not enabled by default on/as system service, you may want to create your own systemd entry for enabling it every start-up

Some of the settings can be configured through Settings >> Sharing >> Screen Sharing the rest is through ~$ gsettings set org.gnome.Vino ANY_EXISTING_KEY NEW_VALUE

2
  • For any readers that stumbled upon this comment : the weird thing is, there's no (as far as i can search, up until this comment is posted) any recent documentation regarding /usr/lib/vino/vino-server for current(~18.04) or recently-previous Ubuntu versions Jul 17 '20 at 21:58
  • That is because vino-server is basically VNC minus all the configuration options. And vino-server can not be started from systemd as suggested because it requires an active session. (you need to be logged into your desktop first)
    – Seb
    Nov 13 '20 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.