VNC on ubuntu via CLI
By default a fresh ubuntu install comes without ssh nor vnc.
If installing ssh is as easy as
1sudo apt install ssh
enabling 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
1sudo apt install vino
User intervention (optional)
Disable any user intervention for establishing the connection (the default configuration requires an user to accept a remote connection)
1gsettings set org.gnome.Vino prompt-enabled false
Disable connection notification (optional)
You can disable the connection notification popup.
1gsettings set org.gnome.Vino notify-on-connect false
Set VNC as view-only (optional)
Maybe you don’t want to interfere to what the user is doing.
1gsettings set org.gnome.Vino view-only true
Encryption (optional)
Sadly a lot of VNC clients doesn’t support encryption, this is to get rid of it
1gsettings set org.gnome.Vino require-encryption false
Authentication
Just choose if you want it without any password request or a specific password.
No password authentication
1gsettings set org.gnome.Vino authentication-methods "['none']"
Fixed password authentication
Replace “mypassword” with a sensible one
1gsettings set org.gnome.Vino authentication-methods "['vnc']"
2THEPASS=$(echo -n mypassword | base64)
3gsettings 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:
1nmcli connection show
2
3NAME UUID TYPE DEVICE
4Connessione via cavo 1 6a2988c0-3a73-37a7-943a-7529bcd78462 ethernet ens160
5Connessione via cavo 2 628a3436-7e7f-3299-abca-664418ffb382 ethernet ens192
And then we can bind the vnc server to a single connection:
1dconf write /org/gnome/settings-daemon/plugins/sharing/vino-server/enabled-connections "['6a2988c0-3a73-37a7-943a-7529bcd78462']"
Or to multiple connections:
1dconf 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:
1export DISPLAY=:0
2/usr/lib/vino/vino-server &