Categories: Raspberry PiTutorials

Setting up Remote Desktop in Raspberry Pi – Part 4

Remote Desktop

SSH is often all you need to control your Raspberry Pi, however sometimes it is useful to be able to remote control your Raspberry Pi using the mouse and seeing just what you would see on the screen of the Raspberry Pi. VNC (Virtual Network Connection) is a standard for doing just this. To use it, you have to install some software on your Pi. There are a number of VNC server applications, and the one we are going to use is called “tightvnc”.

Installing a VNC Server

Enter the following command,

sudo apt-get update
sudo apt-get install tightvncserver

You will be prompted to confirm installation by typing “Y‘ and finally when installation is complete, start the server:

vncserver :1

You will be prompted to enter and confirm a password. The passwords are limited to 8 characters. Note that, this is the password that you will need to use to connect to the RaspberryPi remotely. There is no need to create a view only password, unless you have a specific need.

Adding Tightvnc to the startup

To have TightVNC start up automatically we need to create a new init file.

sudo nano /etc/init.d/tightvncserver

Add the below code in the file,

#!/bin/sh
### BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop tightvncserver
### END INIT INFO

### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
### End customization required

eval cd ~$USER

case "$1" in
start)
su $USER -c '/usr/bin/tightvncserver :1'
echo "Starting TightVNC server for $USER "
;;
stop)
pkill Xtightvnc
echo "Tightvncserver stopped"
;;
*)
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
;;
esac
exit 0

Change the Username ‘pi’ to whatever you have set for your Pi.

Set ownership, file permissions and run level with the below commands,

sudo chown root:root /etc/init.d/tightvncserver
sudo chmod 755 /etc/init.d/tightvncserver
sudo update-rc.d tightvncserver defaults

Use below commands to manually start and stop the VNC.

sudo /etc/init.d/tightvncserver start
sudo /etc/init.d/tightvncserver stop

Connecting from VNC Client

There are many VNC clients available such as Real VNC Viewer, UltraVNC and so on. Download and install any of the VNC Client in your PC. The basic mandatory setting that you have put is the IP address of your Raspberry Pi and the VNC server port.
Enter the IP address and Port number of the server like this,
192.168.2.3:1
:1 is the port number that you set for the VNC Server in Raspberry Pi.


Finally, the VNC window itself should appear. As with SSH, since this is working over your network, your Pi could be situated anywhere, as long as it is connected to your network


Shamnad T

I love working with electronics, embedded specifically. I also have some experience in MATLAB and CAD software. Very much interested in Arduino and Raspberry Pi.

Share
Published by
Shamnad T

Recent Posts

How to determine which Raspbian/Debian version is running on your Raspberry Pi

We all know that Raspberry Pi can run several types OS images, not just limited…

8 years ago

10% Discount on Fee for BTech/BE Engineering Project Guidance

DIGX is offering 10% fee discount on Project Guidance registrations till August 31, 2016. Grab…

8 years ago

Register for your Embedded project and get FREE Arduino Kit

A golden reason for learning and completing your final year engineering project in DIGX is…

9 years ago

The new Raspberry Pi Model B+ arrived

The new devil There's a new sweet devil out for tech savvies, the new Raspberry…

10 years ago

Setting up and Automatically Connecting Wi-Fi on Raspberry Pi – Part 3

It's quite often that we use our RaspberryPi for some mobile applications like a robot…

10 years ago