As gaining remote access to an Ubuntu Desktop machine is only possible when the user is logged into the X interface, it could be interesting to start the VNC automatically on boot. My description is based on the following article.

To set it up, follow these steps:

  1. First, install the TightVNC server. It can be installed with Synaptic, or with 
    sudo aptitude install tightvncserver
  2. Set up the VNC server for the user you wish to log in as. When you run “vncserver” for the first time, it will ask you to set a password. VNC authentication is not the strongest encryption available, so be sure to firewall your server from all but trusted machines. To launch programs or a session when your VNC session starts, modify 

    Here is an example of xstartup: it runs an icewm session and K3B. For Gnome, try running “gnome-session”, and for KDE, try “startkde”.

    xrdb $HOME/.Xresources
    xsetroot -solid black
    k3b &
    icewm-session &
  3. Copy the following into 

    Be sure to change the “USER” variable to whatever user you want the VNC server to run under.

    #!/bin/sh -e
    # Provides:          vncserver
    # Required-Start:    networking
    # Default-Start:     3 4 5
    # Default-Stop:      0 6
    ### END INIT INFOPATH="$PATH:/usr/X11R6/bin/"
    # The Username:Group that will run VNC
    export USER="myuser"
    #${RUNAS}# The display that VNC will use (this correspond to the port)
    # Display 1 --> Listening on port 5901
    # Color depth (between 8 and 32)
    # The Desktop geometry to use.
    # The name that the VNC Desktop will have.
    OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
    case "$1" in
    log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
    su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
    log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
    su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
    $0 stop
    $0 start
    exit 0
  4. Make the script executable with 
    sudo chmod +x /etc/init.d/vncserver

    Then, run

    sudo update-rc.d vncserver defaults

    This adds the appropriate symlinks to the vncserver script so that it is sent the start and stop commands at the appropriate time.

  5. To start the server without rebooting, run 
    sudo /etc/init.d/vncserver start
  6. Finally, connect to your server with a VNC client on port 590X, where X is the value of “DISPLAY” in the vncserver script.
Categories: Geek stuffLinux

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts


Internet in 3D

Imagine: Internet, 2.4 billion users, a map. How could we represent this in a clear 3D view ? The Internet Map application for iOS and Android is able to represent this in a clear view. Read more…


Preferring IPv4 over IPv6 for apt-get

As more and more hosts are moving over to IPv6, you might encounter DNS A records with IPv6 entries. That’s all fine, but sometimes networks or firewall filters are not well configured and you loose Read more…


NAT with iptables on Linux

Just trying to configure NAT on a Linux Backtrack with two ethernet cards (eth1 is inside and eth0 is outside) and I would like to share here the configuration I made: Activation of the IP Read more…