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.

Comments

author
gtoal (author)2017-05-28

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.)

author
MatthewH (author)gtoal2017-07-06

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

author
gtoal (author)MatthewH2017-07-06

Yes! That is indeed the answer I was looking for - thanks!

author
whitev6 made it! (author)2016-10-31

It worked the first time. This is the only walk-thru I've been able to find that honestly works !!

Pi Zero

Macbook Air

Screen Shot 2016-10-31 at 2.29.31 PM.png
author
vasos047 (author)2016-03-15

This is not working if rpi is connected over 3G.

Any ideas how to solve this?

author
MatthewH (author)vasos0472016-03-15

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.).

About This Instructable

22,271views

75favorites

License:

More by MatthewH:Create a Joystick Using the Arduino Joystick Library 2.0Remote Control Your Raspberry PiUltimate Classic Game Console Joystick to USB Adapter
Add instructable to: