Pinterest Stumbleupon Whatsapp
Ads by Google

Your Raspberry Pi is an amazing little computer, but it can be a bit inconvenient. Under normal use, you need to plug in a keyboard and mouse and hook it up to a HDMI monitor VNC, SSH and HDMI: Three Options for Viewing Your Raspberry Pi VNC, SSH and HDMI: Three Options for Viewing Your Raspberry Pi The Raspberry Pi is a remarkable little computer, but it can be time consuming to set it up and connect it to your monitor. Read More (although other displays can be used) in order to view the command line or desktop.

However, this isn’t always practical. You’re probably using your monitor for your main PC. Or, it might be your main TV. Whatever the situation, there comes a time when you find that it would just be a whole lot easier to remotely connect to your Raspberry Pi.

We’ve previously explained how to connect using SSH Setting Up Your Raspberry Pi For Headless Use With SSH Setting Up Your Raspberry Pi For Headless Use With SSH The Raspberry Pi can accept SSH commands when connected to a local network (either by Ethernet or Wi-Fi), enabling you to easily set it up. The benefits of SSH go beyond upsetting the daily screening... Read More , which delivers remote command line access. But what if you need access to the Raspberry Pi desktop from your PC or laptop?

This is where VNC comes in.

What Is VNC?

Virtual Network Computing uses the remote frame buffer protocol to give you control of another computer, transmitting keyboard and mouse input to the remote computer and sending output back across the network to your display.

This means that you can launch programs remotely on your Raspberry Pi, adjust settings in the Raspbian GUI and generally use the desktop environment much as you would with the Pi plugged into your monitor.

Ads by Google

Up until recently, my own preferred VNC solution for Windows to Pi connections was via TightVNC, a VNC solution that is lightweight Is TightVNC Really More Tight Than Other VNC Clients? Is TightVNC Really More Tight Than Other VNC Clients? When it comes to remotely connecting to a desktop PC or a server, most people quickly opt for installing a VNC server. It's fast, easy to configure, and best of all it's absolutely free. Once... Read More , if a little sluggish.

Using TightVNC to Remote Connect to Your Raspberry Pi

Setting up remote access to your Raspberry Pi with TightVNC is simple. Begin by running a package update:

sudo apt-get update

…before proceeding to install the TightVNC server for Linux:

sudo apt-get install tightvncserver

Note that you can either do this with your monitor plugged in, or remotely using the command line via SSH.

With the server application installed run it:

tightvncserver

Finish by starting the VNC server:

vncserver :0 -geometry 1920x1080 -depth 24

This creates a session on display 0 – keep a note of this as you will need it when you connect.

muo-raspivnc

To connect to this server session, you’ll first need to install TightVNC on your desktop computer. Linux users should simply install the TightVNC viewer:

sudo apt-get install xtightvncviewer

Meanwhile, Windows and Mac OS X users can download the client from www.tightvnc.com/download.php. Make sure you launch TightVNC Viewer on your computer, as the download package will also install TightVNC Server on your PC.

With the TightVNC Viewer running, enter the IP address or device name of your Raspberry Pi, followed by a colon and the number of the sessions. For instance, to connect to session 0, created above, enter MyRaspberryPi:0, replacing “MyRaspberryPi” with your own device name or IP address.

Run VNC at Boot

As things stand, this will only work if you run tightvncserver each time you reboot the Raspberry Pi, which means first establishing an SSH connection – not ideal! However, you can overcome this by creating a startup script.

Begin by creating a new file in nano:

sudo nano vnc.sh

and entering the following script:

#!/bin/sh
vncserver :0 -geometry 1920x1080 -depth 24 -dpi 96

With this entered, press CTRL+X to exit the text editor, selecting Y to save. Next, set the permissions:

sudo chmod +x vnc.sh

You can run this by entering

./vnc.sh

Another script is now required, but first you’ll need to login as root, and navigate to the correct directory:

sudo su
cd /etc/init.d/

Create another file in nano, this time called vncboot:

sudo nano vncboot

Enter the following (copy and paste should work, but check that it hasn’t pasted multipe times).

#! /bin/sh
# /etc/init.d/vncboot

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
;;

stop)
echo "Stopping VNC Server"
/usr/bin/vncserver -kill :0
;;

*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
;;
esac

exit 0

Next, make the file executable:

chmod 755 vncboot

Finish with

update-rc.d /etc/init.d/vncboot defaults

…or if this doesn’t work…

update-rc.d vncboot defaults

You can test this is working by rebooting your Raspberry Pi, and attempting a VNC connection from your PC.

Once up and running, you should be able to interact with most desktop apps and settings. Some users find TightVNC slow, however. Fortunately there is an alternative – a sort of VNC over SSH solution.

VNC over SSH with Xming

If you have followed our guide to SSH, or have previously used the service, you will know that such connections are operated via an SSH client. On Windows, this is probably PuTTY, which you should have installed already.

Windows users can take advantage of Xming, a VNC-style solution that offers faster performance and additional reliability. Like standard SSH, however, this depends on SSH being enabled on your Raspberry Pi, which you can do using raspi-config What You Need to Know About Getting Started with Raspberry Pi What You Need to Know About Getting Started with Raspberry Pi The Raspberry Pi computer is the latest in a line of compact, multi-function devices, shipped as a barebones package so that end users can use the hardware for virtually any computing project that comes to... Read More  (it’s enabled by default).

Get started by downloading Xming from Sourceforge and installing, confirming that the PuTTY link is selected in the installation wizard.

Once Xming is installed, find the desktop shortcut, right-click and select Properties. In the Target field, ensure that the file address is appended as follows:

“C:\Program Files (x86)\Xming\Xming.exe” :0 -clipboard -multiwindow

muo-rpi-vnc-xming-properties

If the text in bold is not present, add it in and click Apply.

When done, launch Xming. Windows Firewall will attempt to block the program, so wait for this box to appear and click Allow.

muo-rpi-vnc-xming-forwarding

We’re nearly there. In PuTTY, expand the menu tree on the left and go to Connection > SSH > X11. Here, check Enable X11 forwarding. Return to the Session view, then enter the IP address or device name for your Raspberry Pi, perhaps saving the session if you plan on using those settings again.

Click Connect – seconds later, you’ll be enjoying a virtual desktop experience over SSH!

Remote Connect Using Microsoft RDP

Another option for remote connections between desktop PCs and Raspberry Pi is Microsoft RDP. This is built into Windows Vista and later, so no additional software is required on your PC.

On your Raspberry Pi, open a Terminal window and install xrdp.

sudo apt-get install xrdp

Once installed, this will run whenever an authenticated connection is made from your PC, as xrdp runs as a service. Launch Remote Desktop Connection in Windows (W8.x and later can simply search for “rdp” to find this) and in the Computer field, input the IP address of your Pi. When you click connect, Windows should ask you to confirm connection, as the identity of the target computer will not be clear. As you know that it is your Raspberry Pi, and on your network, it is safe to proceed.

muo-rpi-vnc-windows-rdp

When prompted, input the username and password of your Pi account. If, for example, you hadn’t changed the defaults Securing Your Raspberry Pi: From Passwords to Firewalls Securing Your Raspberry Pi: From Passwords to Firewalls Anyone can use Google to find the default username and password of your Raspberry Pi. Don’t give intruders that chance! Read More , this would be username: pi and password: raspberry.

In a moment, you should be remotely connected to your Raspberry Pi!

We’re looked at three remote desktop solutions for the Raspberry Pi. Which is your favorite? Do you use different remote desktop tools? Tell us about it in the comments.

  1. Steve Shiflett
    October 8, 2016 at 10:32 pm

    Odd. I installed xrdp to get things going - and ended up with this problem:

    connecting to sesman ip 127.0.0.1 port 3350
    sesman connect ok
    sending login info to sesman
    login successful for display 10
    started connecting
    connecting to 127.0.0.1 5910
    error - problem connecting

    I dinked around reading how to fix it - at last did

    sudo apt-get remove xrdp
    sudo apt-get update
    sudo apt-get xrdp

    I believe the update may have helped... but it works fine now. Thank you for posting this most useful article.

    BTW, I started to go the VNC route - but thought, "xrdp is much easier - let's make it work".

    • Christian Cawley
      October 9, 2016 at 9:52 pm

      Hi Steve. Glad you got it sorted, thanks for sharing your fix.

  2. Jeff
    July 26, 2016 at 3:40 pm

    I have tried the XMing on several different systems since I first read about it. I've never managed to get it to do anything.

    • Christian Cawley
      July 26, 2016 at 7:04 pm

      What sort of problems did you have?

      • Jeff
        July 26, 2016 at 8:39 pm

        Nothing really. These instructions are very similar to what I have read elsewhere. Once the Xming program is running and the X11 forwarding is set in putty, the terminal window will open, ask for login info, and go to the command line, just like it always does. No x server opens in windows. checked the log, saw this:

        Xming :0 -multiwindow -clipboard

        XdmcpRegisterConnection: newAddress 192.168.0.135
        winCheckDisplayNumber - CreateMutex failed: Access is denied.

        Fatal server error:
        InitOutput - Duplicate invocation on display number: 0. Exiting.

        winDeinitMultiWindowWM - Noting shutdown in progress

        So I tried it with display 1. That, at least, got a much longer log entry.

        Started Putty with X11 forward. Nothing. Tried sudo startx. Nothing.

        Like I said, never seen it do a thing.

        • Christian Cawley
          July 27, 2016 at 8:29 am

          Interesting. Possible firewall issue in Windows?

  3. Aryldo Russo
    June 16, 2016 at 6:32 pm

    Great article.

    I tried Tightvnc and rdp. Both worked but only in a different window, so I cannot see what is going on the pi screen.

    With Xming, I could not have any window.
    Xming log says : winClipboardProc - XOpenDisplay () returned and successfully opened the display.
    and putty says :modprobe: FATAL: Module g2d_23 not found.

    Aryldo

  4. George Pamfilis
    June 12, 2016 at 11:16 am

    A correction in the section "What is vnc" you say "launch problems" do you mean launch programs?

    • Christian Cawley
      June 12, 2016 at 10:27 pm

      Great spot, George, thanks for letting us know.

  5. Matt
    February 8, 2016 at 9:28 pm

    Am I missing something? the XMing method just opens a normal SSH window. No desktop. Surely I need to install something on the Raspberry Pi?

    • Christian Cawley
      February 9, 2016 at 11:51 am

      Try typing start x

      Let me know if that works.

  6. Matt
    January 19, 2016 at 3:01 pm

    Great job. Bookmarked as well. Keep up the good work! :)

  7. DonGateley
    November 28, 2015 at 12:20 am

    Damn fine article. Comprehensive and clear. Bookmarked.

    • Christian Cawley
      November 28, 2015 at 1:14 pm

      Delighted you think so, DonGateley, thanks!

Leave a Reply

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