ubuntu 18.04 connect to login screen over VNC

41,563

Solution 1

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)

Solution 2

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

Solution 3

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)

Share:
41,563

Related videos on Youtube

user3407546
Author by

user3407546

Updated on September 18, 2022

Comments

  • user3407546
    user3407546 over 1 year

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

    • Seb
      Seb almost 6 years
      Need to bind x11vnc to screen instead of session.
    • jb510
      jb510 almost 6 years
      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.
    • Christoph
      Christoph over 5 years
      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?
    • S.V.
      S.V. over 3 years
      I tested @seb solution with Debian 10 with Mate and it worked.
  • ashish
    ashish over 5 years
    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
  • eakst7
    eakst7 over 5 years
    "Restart-sec" should be "RestartSec"
  • Christoph
    Christoph over 5 years
    When you say "fake monitor" for headless, do you mean xserver-xorg-video-dummy?
  • Lapshin Dmitry
    Lapshin Dmitry about 4 years
    As a note: never create your own config files in /lib, use /etc: /etc/systemd/system
  • Seb
    Seb about 4 years
    Modified to include suggested changes from comments.
  • Tommy Aria Pradana
    Tommy Aria Pradana almost 4 years
    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
  • BjornW
    BjornW over 3 years
    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
    BjornW over 3 years
    It seems weird to have to switch away from the Ubuntu default login manager (even if it is "actively developed". Is this still required? I tested the latest TigerVNC and it hangs at the Ubuntu 18.04LTS login prompt, you can't enter your password. There is no way to just skip the login screen and just go straight into the desktop? Or maybe that doesn't help the underlying problem (whatever that is...)
  • BjornW
    BjornW over 3 years
    Update: this might work in the latest tigervnc (1.11 as of this writing); I installed it from the .deb into 18.04LTS and it seems it starts correctly (and no login prompt). I did switch to lightdm just before, so maybe it had some effect, but I'm going to switch back to gdm3 and see if it still works :)
  • Seb
    Seb over 3 years
    @BjornW You can enable auto-login with a specified user account in almost all of the greeters should you wish to avoid logging in, which is obviously very insecure. The reason for wanting to attach VNC to the greeter instead of an active session after login is because if your computer reboots, due to for example a power outage, logout by automatic security updates or by accident, your session will terminate. When your session terminates so will VNC and you will no longer be able to connect to VNC until you are back at your computer to physically login first.
  • Seb
    Seb over 3 years
    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
    Seb over 3 years
    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)