Tutorial VNC Server on Linux Debian Bookworm

VNC


To set up an X11 VNC server on Debian, the recommended package is x11vnc, which provides remote access to an existing X session. Alternatively, you can use other VNC servers like TightVNC or TigerVNC to create a new, virtual X desktop session. 

Using x11vnc to Access the Current Desktop 

x11vnc is ideal for remote assistance or accessing the same desktop visible on the physical monitor. 

Installation:

sudo apt update && sudo apt install x11vnc

Configuration and Usage:

Set a VNC password (optional but highly recommended):

x11vnc -storepasswd

This creates a password file, typically located at ~/.vnc/passwd.

Run the server:

To run it in your current terminal session, use:

x11vnc -display :0

You will likely need to use the -auth option or set the XAUTHORITY environment variable to grant x11vnc permission to connect to the X server. 

x11vnc -auth -forever -loop -noxdamage -repeat -rfbauth ~/.vnc/passwd -rfbport 5900 -shared ncache_cr -ncache 10

-forever: keeps x11vnc running after a client disconnects.
-shared: allows multiple clients to connect simultaneously.

Connect securely via SSH tunnel (recommended over direct connection):

VNC does not use secure protocols by default. On your local machine, set up an SSH tunnel and then point your VNC client to localhost:5900:
bash

ssh -L 5900:localhost:5900 -C -N -l your_username your_server_ip

Once the tunnel is active, use a VNC viewer to connect to localhost:5900

Using TightVNC (or TigerVNC) for a Virtual Session 

If you don't have a physical monitor attached or want to run a separate, independent graphical session, tightvncserver is a common choice. 

Installation:

sudo apt update
sudo apt install tightvncserver xfce4 xfce4-goodies dbus-x11

Installing a lightweight desktop environment like Xfce is often necessary on a server without a default GUI. 

Configuration and Usage:

Set a VNC password:

vncserver

Follow the prompts to set a password and optionally a view-only password. This command also creates initial configuration files and starts a server instance (e.g., on display :1, port 5901).

Stop the VNC instance to configure its startup script:

vncserver -kill :1

Configure the xstartup file to use your chosen desktop environment (e.g., Xfce). Back up the original file, then edit the new one:

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
nano ~/.vnc/xstartup

Add the following lines to the ~/.vnc/xstartup file:

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

Save the file and make it executable:

chmod +x ~/.vnc/xstartup

Start the VNC server:

vncserver

It will start a new session on port 5901 (display :1).

Connect from a client using the same SSH tunneling method as with x11vnc, but ensure the ports match the VNC server instance (e.g., 5901). 

Comments

Popular posts from this blog

Tutorial Expo React Native Google AdMob

Tutorial React Navigation React Native