VNC on ubuntu via CLI

By default a fresh ubuntu install comes without ssh nor vnc.
If installing ssh is as easy as
sudo apt install sshenabling VNC via command line is not so trivial.
Just follow these steps as a regular user, superuser provileges are required only for some of them.
Make sure we have the vino package installed
sudo apt install vinoUser intervention (optional)
Disable any user intervention for establishing the connection (the default configuration requires an user to accept a remote connection)
gsettings set org.gnome.Vino prompt-enabled falseDisable connection notification (optional)
You can disable the connection notification popup.
gsettings set org.gnome.Vino notify-on-connect falseSet VNC as view-only (optional)
Maybe you don’t want to interfere to what the user is doing.
gsettings set org.gnome.Vino view-only trueEncryption (optional)
Sadly a lot of VNC clients doesn’t support encryption, this is to get rid of it
gsettings set org.gnome.Vino require-encryption falseAuthentication
Just choose if you want it without any password request or a specific password.
No password authentication
gsettings set org.gnome.Vino authentication-methods "['none']"Fixed password authentication
Replace “mypassword” with a sensible one
gsettings set org.gnome.Vino authentication-methods "['vnc']"
THEPASS=$(echo -n mypassword | base64)
gsettings set org.gnome.Vino vnc-password "$THEPASS"Start the server
The VNC server is bound to a network connection profile. First, we have to get the id of the profile:
nmcli connection show
NAME UUID TYPE DEVICE
Connessione via cavo 1 6a2988c0-3a73-37a7-943a-7529bcd78462 ethernet ens160
Connessione via cavo 2 628a3436-7e7f-3299-abca-664418ffb382 ethernet ens192And then we can bind the vnc server to a single connection:
dconf write /org/gnome/settings-daemon/plugins/sharing/vino-server/enabled-connections "['6a2988c0-3a73-37a7-943a-7529bcd78462']"Or to multiple connections:
dconf write /org/gnome/settings-daemon/plugins/sharing/vino-server/enabled-connections "['6a2988c0-3a73-37a7-943a-7529bcd78462','628a3436-7e7f-3299-abca-664418ffb382']"Manually Start the server
With this commands you can manually start the server, without relying on network profile association:
export DISPLAY=:0
/usr/lib/vino/vino-server &