Home Tutorials Raspberry Pi Setting up Remote Desktop in Raspberry Pi – Part 4

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,

# 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

### 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
su $USER -c '/usr/bin/tightvncserver :1'
echo "Starting TightVNC server for $USER "
pkill Xtightvnc
echo "Tightvncserver stopped"
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
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,
: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