17

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 ¯_(ツ)_/¯

flower42
  • 309

6 Answers6

20

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)
Seb
  • 321
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

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
Nmath
  • 12,664
Francois
  • 11
  • 2
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 :

reyman64
  • 261
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

Tommy Aria Pradana
  • 377
  • 1
  • 4
  • 17