Your Raspberry Pi is an amazing little computer, but it can be a little fiddly. In normal use, you need to connect a keyboard and mouse and connect them to an HDMI monitor (although other displays may be used) to view the command line or desktop.

However, this is not always practical. You are probably using your main computer monitor. Or it could be your main TV. Regardless of the situation, there comes a point when you find that it would be much easier to remotely connect to your Raspberry Pi.

We have previously explained how to connect using SSH. which provides remote access to the command line. But what if you need access to your Raspberry Pi desktop from your PC or laptop?

This is where VNC comes in.

What is VNC?

Network Virtual Computing uses the Remote Frame Buffer Protocol to give you control over another computer by passing keyboard and mouse input to the remote computer and sending output over the network to your display.

This means you can run programs remotely on your Raspberry Pi, tweak settings in the Raspbian GUI, and generally use the desktop environment just as you would if the Pi was connected to your monitor.

Until recently, my preferred VNC solution for Windows connections to the Pi was via TightVNC, a lightweight VNC solution. if a little sluggish.

Using TightVNC to Connect to Raspberry Pi Remotely

Setting up remote access to your Raspberry Pi with TightVNC is very easy. Start by running a package update:

sudo apt-get update 

… Before proceeding with the installation of the TightVNC server for Linux:

 sudo apt-get install tightvncserver 

Note that you can do this with a connected monitor or remotely using the command line via SSH.

Once the server application is running, run it:

 tightvncserver 

Finish by starting the VNC server:

 vncserver :0 -geometry 1920x1080 -depth 24 

This creates a session on display 0 — remember this as you will need it when you connect.

Iy-raspivnc

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

 sudo apt-get install xtightvncviewer 

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

When TightVNC Viewer is running, enter the IP address or device name of the Raspberry Pi followed by a colon and the number of sessions. For example, to connect to session 0 created above, type My Raspberry Pi: 0 replacing «MyRaspberryPi» with your own device name or IP address.

Start VNC on boot

As things stand, this will only work if you run thinvncserver when every reboot of the Raspberry Pi, which means establishing an SSH connection first — not ideal! However, you can overcome this by creating a startup script.

Start by creating a new file in nano:

 sudo nano vnc.sh 

and enter the following script:

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

Once entered, press CTRL + X to exit the text editor and select Y to save. Next, set permissions:

 sudo chmod +x vnc.sh 

You can run this by typing

 ./vnc.sh 

Now another script is required, but first you need to login as root and change to the correct directory:

 sudo su cd /etc/init.d/ 

Create another file in nano, this time named vncboot:

 sudo nano vncboot 

Enter the following (copy and paste should work, but make sure they are not pasted multiple 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 

Then make the file executable:

 chmod 755 vncboot 

do away with

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

…or if that doesn’t work…

 update-rc.d vncboot defaults 

You can check if this works by rebooting your Raspberry Pi and trying to establish a VNC connection from your PC.

Once launched, you will be able to interact with most applications and desktop settings. However, some users find TightVNC slow. Fortunately, there is an alternative — a solution like VNC over SSH.

VNC over SSH with Xming

If you have followed our SSH guide or have used the service before, you will know that such connections are made through an SSH client. On Windows, it’s probably PuTTY, which you should have already installed.

Windows users can take advantage of Xming, a VNC-style solution that offers better performance and added reliability. However, as with standard SSH, this depends on whether SSH is enabled on the Raspberry Pi, which can be done using raspi-config. (it is enabled by default).

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

Once Xming is installed, find the shortcut on your desktop, right-click and select » Properties». In field » Target» make sure the file address is added like this:

«C:\Program Files (x86)\Xming\Xming.exe» : 0 -clipboard -multi-window

ui-rpi-vnc-xming-property

If the bold text is missing, add it and click » Apply» .

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

muo-rpi-vnc-xming-forwarding

We are almost 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, possibly saving the session if you plan to use these settings again.

Click » Connect» — in a few seconds you will be enjoying a virtual desktop over SSH!

Remote connection 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 computer.

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

 sudo apt-get install xrdp 

Once installed, it will run whenever an authenticated connection is made from your computer because xrdp is running as a service. Launch «Remote Desktop Connection» in Windows (W8.x and later can just search for «rdp» to find it), and in the «Computer» field enter your Pi’s IP address. When you click «Connect», Windows should ask you to confirm the connection, as the identity of the target computer will not be clear. As you know it’s your Raspberry Pi, and on your network, it’s safe to proceed.

ii-rpi-vnc-windows-rdp

When prompted, enter the username and password of your Pi account. If, for example, you have not changed the default values this will be the username: pi and password: raspberry .

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

We will cover three remote desktop solutions for Raspberry Pi. Which is your favorite? Do you use various remote desktop tools? Tell us about it in the comments.

Похожие записи