How to use XDMCP to create a login prompt for VNC sessions


The basic process for giving yourself a login prompt to a Linux box via vncviewer is:

  1. Install the vncserver package for your distribution
  2. Find out which display manager you are running and enable XDMCP remote logins
  3. Test to make sure your XDMCP is working
  4. Add connection details to /etc/services
  5. Using either inetd or xinetd configure an Xvnc session on the ports specified in step 3.
  6. Make it secure

    1. Make sure you have the vncserver package for you Linux distribution

    This may be any of the following

    vncserver

    vnc4server

    tighvncserver

    or other.

    Sometimes you have to try different VNC server packages until one works


    2. Find out if you are using a display manager or not

    ps -ef | grep dm
    /usr/bin/gdm-binary -nodaemon

    Depending on what desktop environment you are runing this could be gdm | xdm | kdm enabling XDMCP on each display is covered in the next few sections

    Enabling XDMCP on KDE/KDM (Mandrake 9.1)

    vi /etc/sysconfig/desktop

    # add DISPLAYMANAGER

    DESKTOP=KDE
    DISPLAYMANAGER=KDM

    vi "/etc/X11/xdm/Xaccess"

    # add a line with 'localhost' as the only entry 
    # delete the `*' this will stop it accepting Xdmcp logins from any host

    localhost

    vi /usr/share/config/kdm/kdmrc

    # Enable Xdmcp
    [Xdmcp]
    Enable=true

    Enabling XDMCP on GDM (on RedHat 9.0 or any gdm based system)

    gdmsetup

    # enter root password
    # make sure the Enable XDMCP option is enabled

    Change the gdm.conf file to read as follows
    [xdmcp]
    # Enable=false change it to true
    Enable=true

    On CentOS 5.2 gdmsetup will look as follows

    Enable plain Style login


    Uncheck Honor indirect request leave the rest as the defaults.



    XDM Setup

    /etc/X11/xdm/Xaccess

    *                                       #any host can get a login window

    /etc/X11/xdm/xdm-config

    ! SECURITY: do not listen for XDMCP or Chooser requests
    ! Comment out this line if you want to manage X terminals with xdm
    ! DisplayManager.requestPort:   0


    3. Testing to see if your XDMCP is working

              you may have to either reboot or just run telinit 3 then telinit 5 to bring the display manager down then up to get XDMCP working.

    # make sure you have the XFree86-Xnest package installed then run
     Xnest :3 -query localhost
    # should produce a login window as follows


    4. Editing the /etc/services File

    # add this to /etc/services

    vnc-800x600    5901/tcp            # vnc 800x600 session
    vnc-1024x768    5902/tcp            # vnc 1024x768 session


    5. Editing xinetd.d or inetd.conf configuration

    xinetd.d config

    # create two files for xinet.d to handle launching the Xvnc server in /etc/xinetd.d/

    # note that the name in /etc/services does not dictate what size of screen but is simply a description. You need to edit the -geometry parameter to get the screen size you want.

    service vnc-800x600

    {
    disable = no
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    server = /usr/X11R6/bin/Xvnc
    server_args = :1 -inetd -query localhost -geometry 800x600 -depth 16 -once
    # note on some brands of linux the server value will be /usr/bin/Xvnc (check yours for the correct value)
    # also the server_args value may need -securitytypes=none to stop the remote vncviewer being prompted for a
    # vnc password instead of the GDM/XDM login prompt
    }
    service vnc-1024x768
    {
    disable = no
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    server = /usr/X11R6/bin/Xvnc
    server_args = :2 -inetd -query localhost -geometry 1024x768 -depth 16 -once
    # note on some brands of linux the server value will be /usr/bin/Xvnc
    # also the server_args value may need -securitytypes=none to stop the remote vncviewer being prompted for a
    # vnc password instead of the GDM/XDM login prompt
    }
    I have recently tried this on CentOS 5.2 with this xinet.d config

    service vnc-800x600

    {
            disable = no
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = nobody
            server          = /usr/bin/Xvnc
            server_args     = -inetd -query localhost -geometry 800x600 -depth 16 -once -securitytypes=none
    }

    service vnc-1024x768
    {
            disable = no
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = nobody
            server          = /usr/bin/Xvnc
            server_args     = -inetd -query localhost -geometry 1024x768 -depth 16 -once -securitytypes=none
    }

    Ubuntu inetd.conf configuration (tested on Dapper 6.06)

    /etc/inetd.conf

    vnc-800x600     stream  tcp     nowait  nobody  /usr/sbin/tcpd \
    /usr/bin/Xvnc :21 -rfbport 5901 -inetd -query localhost -geometry 800x600 -depth 16 -once
    vnc-1024x768    stream  tcp     nowait  nobody  /usr/sbin/tcpd  \
    /usr/bin/Xvnc :22 -rfbport 5902 -inetd -query localhost -geometry 1024x768 -depth 16 -once

    Note: If you specify a Xvnc server port eg :21 then your vnc port listen port will be 5921 and when launching via inetd then the vnc server will be listening on the wrong port. To make the inetd setup work you need to force Xvnc to use the same port as the one you specify in /etc/services passing the “-rfbport” <portnumber> parameter fixes this i.e. -rfbport 5902

    Restart xinetd

    # run this to get xinet.d to reread it's config
        /etc/rc.d/init.d/xinet.d reload
    or
        service xinetd reload

    # restart X or telinit 3 and then telinit 5 or kill -SIGHUP pid of gdm


    6. Adding Firewall Rules

    # add some firewall rules to stop connections from anywhere except localhost

    iptables -A INPUT -s 127.0.0.1 --dport 177 -j ACCEPT
    iptables -A INPUT -s 0/0 --dport 177 -j DENY


    Troubleshooting

    I recently installed on Debian and had trouble until I did an

     apt-get install xfs