Remote Desktop using VNC

While working out how to use (or some might say abuse) X windows to allow me access the desktop on several remote systems with different desktop environments and window managers I discovered that it is possible to use both XDMCP and VNC with the Raspberry Pi.

This is because the Raspbian distribution includes the LightDM display manager, and since this is also included in most recent Linux distributions including Debian Wheezy and Ubuntu 11.10 or later the instructions here will apply to machines running these versions as well.

Configuring the Server

To access your Raspberry Pi remotely from another machine using VNC you will need to install the VNC server, and configure the display manager to respond to incoming VNC connections.

To do this you need to open a terminal window and enter the following commands. (If you are using the default Raspbain image then you can open a terminal window by double-clicking on the LXTerminal icon on the desktop).

$ sudo apt-get update
Get:1 http://archive.raspberrypi.org wheezy InRelease [7,737 B]

 :
 :
 :

Fetched 7,505 kB in 47s (159 kB/s)
Reading package lists... Done

$ sudo apt-get install tightvncserver
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  tightvnc-java
The following NEW packages will be installed:
  tightvncserver
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 786 kB of archives.

 :
 :
 :

Setting up tightvncserver (1.3.9-6.4) ...

To configure the display manager to respond to incoming requests we need to edit the configuration file and un-comment all the entries in the VNC Server configuration section, and change the enabled setting from false to true as shown below.


$ sudo vi /etc/lightdm/lightdm.conf
#
# VNC Server configuration
#
# enabled = True if VNC connections should be allowed
# port = TCP/IP port to listen for connections on
#
[VNCServer]
enabled=true
port=5900
width=1024
height=768
depth=8

In order to connect to your Raspberry Pi you will need to know its IP address, underlined below. This may change each time you switch on the Raspberry Pi as it is normally allocated dynamically by your router.


$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:04:4d:89  
          inet addr:xxx.xxx.xx.xx  Bcast:xxx.xxx.xx.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10821 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6054 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14270159 (13.6 MiB)  TX bytes:459755 (448.9 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

For the changes you have just made to take effect you need to restart the display manager.

Note - If you are logged in to the desktop on your Raspberry Pi this will end your current session, so close down any other applications you are using first!


$ sudo /etc/init.d/lightdm restart
[ ok ] Stopping Light Display Manager: lightdm.
[ ok ] Starting Light Display Manager: lightdm.
$ 

Installing the Client

Since this post is really aimed at showing new Raspberry Pi users how to access their Raspberry Pi desktop remotely, and the majority of people who need these instructions will be first time users who are new to Linux I've included instructions on how to install the VNC viewer for both Windows and Linux.

Windows

Depending on which version of Windows you are using you need to download one of the following installation packages.

http://www.tightvnc.com/download/2.6.4/tightvnc-2.6.4-setup-32bit.msi
http://www.tightvnc.com/download/2.6.4/tightvnc-2.6.4-setup-64bit.msi

If you are using an older machine with Windows XP and Service Pack 3 then you will need the 32 bit version, but if you are using Windows 7 then the choice depends on whether you are using a 32-bit or 64-bit version of Windows. To find out right-click on the 'Computer' entry in the start menu and then select 'properties' from the drop down menu. The resulting dialog box will tell you which version you are using.

Save the installation package to your machine and then double-click on it to install the VNC viewer. When the installation is finished there should be a new shortcut to the VNC viewer in the programs menu. Double click on the program icon to start the viewer and enter the IP address of the remote machine when prompted.

You should see the default logon of your Raspberry Pi appear in window.

GDMLightDM Logon Screen

You don't have to use this particular viewer - but it is currently free for personal use and allows you to hide the menu bar which makes for a less cluttered display.

Linux

From a terminal window download and install the viewer package using the following commands.

$ sudo apt-get update
Get:1 http://archive.raspberrypi.org wheezy InRelease [7,737 B]

 :
 :
 :

Fetched 7,505 kB in 47s (159 kB/s)
Reading package lists... Done
$ sudo apt-get install xtightvncviewer
Reading package lists... Done
Building dependency tree       
Reading state information... Done

 :
 :
 :

Do you want to continue [Y/n]? Y

 :
 :
 :

Setting up xfonts-base (1:1.0.3) ...
Setting up xtightvncviewer (1.3.9-6.4) ...
Processing triggers for menu ...
$

To start the VNC viewer from the command line use the following command where xxx.xxx.xx.xx is the IP address of your Raspberry Pi. The '-x11cursor' option is optional, it just tells the viewer to display only the local cursor.

$ xtightvncviewer xxx.xxx.xx.xx -x11cursor

A new window should appear on your local desktop showing the logon screen for your Raspberry Pi.

GDMLightDM Logon Screen


Raspberry Pi is a trademark of the Raspberry Pi Foundation

Advertisements
This entry was posted in Linux and tagged , , , . Bookmark the permalink.

5 Responses to Remote Desktop using VNC

  1. Qian Yan says:

    Hi, Thanks for your post.
    I installed vnc4server, then config the lightdm.conf as you said, but it ask for VNC password when I connect from other host using vnc client. I need to find a way to prevent lightdm ask for password of vnc, or find the option that how to set password for vnc in lightdm..

  2. I followed the instructions exactly, but it still pops up with a password box. No matter what I do (entering something or not), it freezes on ‘connecting’…

  3. Ignore the above, I was using the default mac client which for some reason doesn’t like it!

  4. I have the same password issue and I don’t have a mac. Any clues where passwords are set?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s