Remote Control Your Raspberry Pi
32,494
83
7
Introduction: Remote Control Your Raspberry Pi
Most articles that discuss logging into your Raspberry Pi remotely use xrdp
to create Remote Desktop sessions into your Raspberry Pi. This is often a good solution, and works even if you do not have a physical monitor connected to your Raspberry Pi. But there are times when you actually want to remotely take control of the desktop that is currently being displayed on the physical monitor connected to the Raspberry Pi, rather can creating a new desktop session (which is how xrdp
works). This article explains how to remotely control the desktop currently being displayed on your Raspberry Pi.
Step 1: Open a Terminal Port
Boot up the Raspberry Pi and open a terminal port.
Step 2: Install X11vnc
Enter the following command to install x11vnc
(more information about x11vnc
can be found at http://www.karlrunge.com/x11vnc/):
sudo apt-get install x11vnc
Step 3: Setup VNC Password
Enter the following command to set the VNC password:
x11vnc –storepasswd
This is the password users will need to enter when connecting to the Raspberry Pi.
Step 4: Determine the Raspberry Pi's IP Address
You will need to know the Raspberry Pi's IP Address to remotely connect to it. This can be done by executing the following command from a terminal prompt:
ifconfig
Step 5: Test the X11vnc Server
You can test the x11vnc
server by entering the following at a terminal prompt:
x11vnc –usepw
Step 6: Testing X11vnc Server
Once the x11vnc
server is running, you should see a message like the one shown above in your terminal window.
Step 7: Installing a VNC Client
To remotely control the Raspberry Pi using Microsoft Windows, you will need to install a VNC client. For this example I am using the TightVNC Viewer (http://www.tightvnc.com/download.php). Download and install this application.
Step 8: Run VNC Client
Start the TightVNC Viewer and enter the IP address of the Raspberry Pi followed by a “:” and the display number, which can be found in the terminal window running x11vnc
(this will normally be a 0, but in our example it happens to be a 2).
Step 9: Enter the VNC Password
Enter the password that was used when setting up x11vnc
.
You should now see and able to control the desktop of the Raspberry Pi.
Step 10: Automatically Startup X11vnc on the Raspberry Pi
Complete the following steps if you want the x11vnc
server to automatically startup anytime you boot your Raspberry Pi.
Create the directory ~/.config/autostart
, if it does not already exist. This can be done using the following terminal command:
mkdir –p ~/.config/autostart
Step 11: Create Xterm-autostart.desktop
Create a text file in this directory, called xterm-autostart.desktop
. You can create and edit this file with the following terminal command.
leafpad ~/.config/autostart/xterm-autostart.desktop
Step 12: Populate the Xterm-autostart.desktop File
Put the following text into this file:
[Desktop Entry] Encoding=UTF-8 Name=x11vnc autostart Comment=Starts the x11vnc server to allow for remote VNC connections. Exec=x11vnc –forever -usepw
Step 13: Reboot Raspberry Pi
Reboot the Raspberry Pi.
Once the Raspberry Pi desktop appears, you should be able to remote control the Raspberry Pi using any VNC Client.

Participated in the
Raspberry Pi Contest 2016
1 Person Made This Project!
- whitev6 made it!
7 Comments
11 months ago on Step 13
Putty for Windows, used to have Xterminal (a wrapper for Cygwin's Xterminal). With that you don't need to install anything on the PI (It after all has X-11). From a local Linux machine (my Debian PC) or another local Pi, I use Xephyr (apt-get install xserver-xephyr). NOTHING to install on the remote Pi (I generally purge realvnc). I can even configure the remote Pi to boot headless through raspi-config, and still have a full local image of a remote 'desktop'.
Locally run the Xephyr (or Putty) x-server application. On local Debian or Pi, I run:
$ Xephyr -ac -screen 1728x972 -br -host-cursor -reset -terminate :3.0 &
$ xterm -display :3.0 &
This starts up a local X-11 server (Xephyr) on port :3.0, with an xterm in it. Then in the xterm terminal display, I run (with appropriate IP):
$ ssh -XfC pi@123.123.123.123 exec startlxde
or
$ ssh -XfC pi@145.136.47.9 exec startlxde-pi
This launches the remote PI's desktop normally, as an X-client, but rather than displaying (serving) it on the remote Pi's X-server/hardware (which may be disabled), the Local machine uses it's hardware and CPU to run the X-server and render the image of the desktop, at local resolution, freeing the tiny remote Pi from doing all the work (Pi's Xserver redering on Pi's hardware, then vnc capturing that and sending it to the local machine, and locally rendering that yet again for you to see).
I use startlxde (the X-client) on the remote (and all my Pis), because unlike startlxde-pi, I get multiple desktop work-spaces without duplicate hardware and monitors and such, even within the remote display. This feature has been in most flavors of Linux for -Decades- now, but the kind folk at Raspberry have disabled this in their startlxde-pi.
You can use this procedure for remote access to most any Linux/Unix machine (even a cloud one) as long as you know the commands to start the desktop you prefer (like startlxde).
Tip 1 year ago on Step 5
Newer versions of x11vnc will require the "-display :0" directive to use the current display.
Also be sure to start x11vnc with the user that is running the display ( eg logged in as the 'pi' username )
5 years ago
Since my rpi is headless it doesn't automatically detect an HDMI display and so it starts with a small desktop display which x11vnc sees. I thought that adding
hdmi_force_hotplug=1
hdmi_drive=2
to /boot/config.txt would force an hdmi mode on reboot.
However it didn't work. x11vnc started up with the same small display. Any ideas?
(This is a different problem and solution from using a vnc server such as tightvnc which creates a new virtual framebuffer, where you can force the screen size using the -geometry option.)
Reply 4 years ago
There is a discussion about this on the Raspberry Pi website: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=19600
Hope that helps,
Matt
Reply 4 years ago
Yes! That is indeed the answer I was looking for - thanks!
6 years ago
This is not working if rpi is connected over 3G.
Any ideas how to solve this?
Reply 6 years ago
This article assumes the Raspberry Pi is on the same LAN as the computer that is remote controlling it. Doing this over the internet introduces a lot more risk and exposure to being hacked, so I am not sure I would recommend doing this over 3G. The Raspberry Pi essentially becomes a “server” in this scenario and opens ports that external computers can connect to. I am not familiar with the 3G specification, but I suspect it does not allow for this. There is probably a solution out there to do something like this, but I think it would involve another server or product (e.g. WebEx, GoToMyPC, etc.).