Ubuntu 21.04 (and up) VNC access to a locked session

Ubuntu 21.04 (and up) VNC access to a locked session

The problem: since Ubuntu 21.04 you can use VNC connection ONLY with an ongoing session (it is a pure screen sharing feature now) and you'll not be able to connect to a locked computer.

Ubuntu 21.04 uses Wayland instead of x11 by default, but there are still no completely compatible VNC servers.

There is only a way to connect to the currently active session with gnome-remote-desktop (installed by default now instead of vino), but not to a locked session.

Note that Settings/Sharing settings configure now gnome-remote-desktop instead of vino!

To be able to login to locked session you'll need to restore vino. First remove gnome-remote-desktop (because even if we install vino, the system would still use gnome-remote-desktop):

sudo apt remove gnome-remote-desktop

(after removing, screen sharing settings would disappear - that's normal!)

Install vino:

sudo apt install vino

But vino wouldn't start automatically so we need to manually add it to autostart:

cd ~/.config/autostart/
vim vino-server.desktop

autostart directory may not exist, in this case, create it first:

mkdir ~/.config/autostart/

With the following content:

[Desktop Entry]
Name[ru]=Vino Server
Name=Vino Server

NOTE: the same configuration could be performed through UI: run Startup applications tool and add a new record there.

With this entry, vino server would start on the first login, so when you lock the session you would still be able to connect. But you'll not be able to connect after the computer restart (first manual login is required).

After that configure vino:

gsettings set org.gnome.Vino prompt-enabled false 
gsettings set org.gnome.Vino vnc-password $(echo -n "mypassword"|base64)

This should be enough, but make sure that you have all the following:

dconf dump /org/gnome/desktop/remote-access/

Note that lock-screen-on-disconnect is optional: without it, you'll have to manually lock the computer before disconnection (otherwise it would remain unlocked).

To simplify configuration you can use dconf-editor: install it from Ubuntu software. Open dconf-editor and go to org/gnome/desktop/remote-access/.

Screenshot from 2021-12-24 16-55-09.png

NOTE: To change password value you'll need to click on vnc-password (last option) and make sure use-default-value is disabled. The custom value must contain the hex form of your password. To verify password hex use:

echo -n "yourpassword"|base64

Now restart, but don't log in!

Vino can't work with wayland and so you'll need to switch session back to x11: on the login screen at the bottom right corner, there is a switcher to use x11 instead of Wayland. Set "Ubuntu on xorg" and log in (the setting should be remembered so next time you'll log in again with x11 - no need to switch every time).

Now lock (not log out!) computer and try connecting with a vnc client (for example, using remmina on linux and mobaXterm on windows).