How to automatically share X session using VNC

Today, I will briefly describe how to automatically share X session on Debian Wheezy using VNC protocol.

First step

Install x11vnc package using the following command.

$ sudo apt-get install x11vnc

Second step

Generate and store password as the end user that will be used for authentication.

$ x11vnc -storepasswd 'MY_PASSWORD' ~/.vnc/passwd

Third step

Create simple shell script to start VNC service at X startup.

# sudo cat /etc/X11/Xsession.d/999vnc << EOF
# Simple shell script to start VNC service on display :0
# for *milosz* user using password stored in *~/.vnc/passwd*
# and listen on ** IP address

if [ "$(whoami)" = "milosz" ]; then
  x11vnc -display :0 -rfbauth ~/.vnc/passwd -listen -ncache 10 -forever &
Replace milosz username and IP address.

Ensure that proper permissions are set.

$ sudo chmod 644 /etc/X11/Xsession.d/999vnc
$ sudo chown root:root /etc/X11/Xsession.d/999vnc

Ending notes

You can also use ~/.xinitrc file to execute VNC service for an end user.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland