Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to access an Ubuntu machine remotely via VNC. But I can access the Ubuntu machine only if the user is logged in. I want to access the ubuntu machine via VNC from the login screen itself. We can access all windows machines from the login screen. However we were not able to access the Ubuntu machine from the login screen. There is some way but I am not aware of the details. Can someone give a solution to this problem?

share|improve this question
If the other machine is on the same LAN it would be feasible to just use XDMCP instead of VNC. If it's not on the same LAN, unaccelerated X over the network might be too slow. – Robin Green Apr 16 '11 at 7:05
up vote 8 down vote accepted

Your best bet is to install xrdp Install xrdp. After installation, you can use an RDP client to connect to the machine - you will then be prompted for your credentials as you would be on the login screen.

share|improve this answer
I have installed xrdp but still i am unable to access the ubuntu machine from the login screen. – karthick87 May 17 '11 at 12:34
@karthick: Are you connecting to the machine with VNC or using an RDP client? – Nathan Osman May 17 '11 at 15:48
I dont find RDP client in my machine. Where it will be located ? – karthick87 May 18 '11 at 5:43
@karthick: Are you using Ubuntu as your client? If so, the program to use is called "Terminal Server Client". On Windows, it's called "Remote Desktop" IIRC. – Nathan Osman May 18 '11 at 6:15
Yeah thank you. Is it possible to create a launcher for Terminal Server Client ? – karthick87 May 18 '11 at 7:05

To enable GDM login over a VNC ssh remote connection try with X11vnc. See also this answer.

share|improve this answer

Overall, I'd recommend x11vnc.


apt-get -y install x11vnc
x11vnc -storepasswd

Enter your password, it's saved by default in ~/.vnc/passwd in INSECURE encrypted form. It can be decrypted because the key is known... protect it with filesystem permissions)

chmod 600 ~/.vnc/passwd

Save my helper script locally:

mkdir ~/bin/
curl  > ~/bin/ && chmod +x ~/bin/

From your VNC Client host:

ssh -f  -L 5900: -p 22 '~/bin/ && sleep 10'

Or, from your VNC Server host, run :


via a terminal (or start it as a daemon with -forever as an init.d service, upstart service, systemd unit, or however you wish)

Now run your VNC Client of choice from your Client Host, point it at:, login with password saved above.

Use the X11 "Magic Cookie"

Most X display managers (like GDM, XDM, KDM) start an initial X11 server and authenticate to it with an MIT Magic Cookie. Depending on your display manager, the magic cookie will be found in one of various locations.

I've had good luck getting a VNC session open on the Ubuntu GDM login screen by finding the magic cookie with this script:

if [ -x /usr/bin/x11vnc ]; then
     [ "$1" == '-nocache' ] && CACHE_FLAG='-noncache' || CACHE_FLAG='-noncache'
     [ "$2" == '-guess' ] && GUESS_FLAG='-auth guess' || GUESS_FLAG=''
         [ -f /root/.vnc/passwd ] && PASSWORD="/root/.vnc/passwd"
         [ -f $HOME/.vnc/passwd ] && PASSWORD="$HOME/.vnc/passwd"
         [ ! -z "$PASSWORD" ] && x11vnc -display :0 -xkb -rfbauth $PASSWORD -rfbport 5900 -shared -forever -nowf -norc -notruecolor -bg $GUESS_FLAG $CACHE_FLAG -noxdamage
     if [ $EXIT_CODE -ne 0 ]; then

        echo "\n*********************************************************************"
        echo "*** Could not start x11vnc!  Trying again with gdm MAGIC_COOKIE! ***"
        echo "*********************************************************************\n"
        MAGIC_COOKIE_FILE=`sudo find /var/run/gdm/ -iname database | grep for-gdm`
        [ -z "$MAGIC_COOKIE_FILE" ] && MAGIC_COOKIE_FILE=`sudo find /var/lib -name '.Xauthority' -o -wholename '/var/run/lightdm/root/:0' | head -n1`
        #sudo bash -c "[ -z \"$MAGIC_COOKIE_FILE\" -a -e /var/run/lightdm/root/:0 ]" && MAGIC_COOKIE_FILE='/var/run/lightdm/root/:0'
        [ ! -z "$PASSWORD" ] && sudo x11vnc -display :0 -xkb -rfbauth $PASSWORD -rfbport 5900 -shared -forever -nowf -norc -notruecolor -bg $GUESS_FLAG $CACHE_FLAG -noxdamage ${AUTH_COOKIE_FLAG}

I can start this script (I called it anytime via SSH... even before login via the gdm login screen. It launches an x11vnc server which I can then connect to over SSH tunnel. (Use ssh -L 5900: or add LocalForward 5900 to your host's entry in ~/.ssh/config).

share|improve this answer

Here's how to do it with VNC, if you don't want to use RDP:

  1. Install X11VNC server : sudo apt-get install x11vnc (Or through Ubuntu Software Center -> X11VNC Server)
  2. Set a password:

    sudo mkdir /etc/x11vnc
    sudo x11vnc -storepasswd /etc/x11vnc/passwd

    Choose y to save the password.

  3. Create an empty file in /etc/init called x11vnc.conf:

    sudo -H gedit /etc/init/x11vnc.conf
  4. Paste this into the file:

    start on login-session-start
    exec x11vnc -xkb -forever -auth /var/run/lightdm/root/:0 -display :0 -rfbauth /etc/x11vnc/passwd -rfbport 5900 -bg -o /var/log/x11vnc.log
  5. Save and close

  6. Restart Ubuntu

That's it! You should now be able to connect with any VNC client even before login.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.