Aug 152011
 

Introduction

This document will describe how to install vnc4server with Xinetd and multiple screen-resolutions on demand.

There will be no authentication used, because we use gdm as XDMCP service, so we can login as different users.

In the end I describe a small solution how to change the display-solution dynamically (in case your vnc-viewer does support this option).  I use the vncviewer module from Ultra-VNC, but any other might work as well.

The enviroment I used for this is a Debian 6.0 based system. With some adaptions this documentation will most likely work on Ubuntu as well as on RPM-based systems like Redhat, CentOS, Fedora, Suse…

Installing needed packets

# VNC-Server
aptitude install vnc4server

# Xinetd (this service will accept connections on the default port and forward it to the vncserver process
aptitude install xinetd

# X-Services
# we need GDM for providing logon functionality
# and we use xfce4 as window-manager, since it is lightweight compared to Gnome or KDE
aptitude install gdm xfce4

Configuring xinetd

First you need to edit/create the file /etc/xinetd.d/Xvnc

service Xvnc {
    type = UNLISTED
    disable = no
    socket_type = stream
    protocol = tcp
    wait = no
    user = root
    server = /usr/bin/Xvnc
    server_args = -inetd -query localhost -once -securitytypes=none -NeverShared -depth 24 -geometry 1800x900 -geometry 1200x768
    port = 5901
}
  • wait = no
    will spawn a new Xvnc-session for each user that connects to port 5901
    existing sessions will be automatically closed if you close the vnc-viewer window
  • server_args= ….
    For whatever reason the file /etc/vnc.conf is not really read by Xvnc (despite a lot of documentation that told something different), so we need to specify
  • -securitytypes=none
    option disables the login via VNC-protocol. We don’t need authentication on vnc-level, because we use xdmcp-service
  • -geometry
    if this option is present more it will allow you to change the display-resolution during you run your VNC-Session (if your vnc-viewer client supports this)
    the geometry specified first will be the default-resolution after you connect.

If you run the program with these settings, please be aware off, that if the connection gets lost all programs that are still running are terminated (XSession ends). It’s not possible to resume a previous session.

A proper login (including XSession) won’t work yet, since the XDMCP service gdm is not yet running. You will get a direct connection to a X-Session without further authentication. Since the Xvnc process is yet started with root-privelidges you will have root-access to the server.

Configuring GDM

Using Debian 6.0 it seems like the gdm.conf is pretty empty. The settings that are available can be found in /usr/share/gdm/defaults.conf and describe the defaults that can be overwritten with the values in /etc/gdm.conf

You have to change/add these two sections /etc/gdm/gdm.conf

[daemon]
    RemoteGreeter=/usr/lib/gdm/gdmlogin

[xdmcp]
    Enable=true

If you try to start the service now using “service gdm start” it will most likely fail, because it cannot connect to an X-Server running on the TTY.

There are two ways to prevent this error. The not sooo elegant way is to edit the startup-script /etc/init.d/gdm. Search for:

start_daemon $DAEMON

and change this line to

start_daemon $DAEMON --no-console

After that you can start the gdm service with “service gdm start”

The better way is to do this: Change the following section in /etc/gdm/gdm.conf as well.

[servers]
    0=inactive

Then you don’t have to change the init-script that might be modified or overwritten by the next system-update.

And as soon as you started the gdm and this one is running properly you should be able to do a VNC-connect get a logon-window and after you logged in you should see your favourite window-manager.

After this amount of text, it’s worth to have some screenshots before we add one last feature to our configuration.

 Screenshots

First we see the connection-dialog of our preferred VNC-Viewer

The connection to the X-VNC-Server establishes and the logon-screen of GDM is shown.

After logging into the system the XFCE-Desktop is shown. Now we could start working
Of course you can logoff from the system as well:

You can also see, that all processes are running with the UID from walter (except the console-sessions, that I’ve started SUID)

Getting xrandr to work

As you can see we specified more than one resolution for the display. For whatever reason I was not able to change the resolution with the xfce4-display-settings program, even though all the possible resolutions where shown.
You can work around this by using the console tool “xrandr” which gives you this nice output

SZ: Pixels Physical Refresh
0 1800 x 900 ( 457mm x 229mm ) 60
*1 1200 x 768 ( 305mm x 195mm ) *60
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none

You can also change to another resolution by using xrandr -s . So I wrote a small script to toggle between both settings.
It is not very beautiful, but nevertheless it works quite fine.

#!/bin/sh
CUR=$(xrandr | grep '*' | awk -F'*' '{print $2}' | awk '{print $1}')
CUR=$((CUR +1 ))
if [ $CUR -gt 1 ]; then
    CUR=0
fi
echo $CUR
xrandr -s $CUR

I’ve added a shortcut on the display and everytime I start the program the resolution changes.

How does this work? Well look at these screenshots:

after double-clicking on the Toggle-Res symbol the screen looks like this:

  •  15. August 2011
  •  Posted by at 10:05
  •   Kommentare deaktiviert für Getting XVNC-Server up and running using Xinetd
  •   Tips&Tricks