Headless Raspberry Pi using SSH and VNC

Posted by Jack L on

When it is not convenient to work directly on the Raspberry Pi or when the Raspberry Pi doesn’t have a display attached to it (known as a headless Raspberry Pi), you can still work on it from another computer remotely.

Remote Raspberry Pi Access using SSH (command line)

The first option is to connect to the Raspberry Pi over SSH (Secure Shell). SSH allows you to remotely gain access to the command line of a Raspberry Pi from another computer over the network or the internet (if your network is setup for it). SSH only allow command line, not a full desktop. For a full graphical desktop, VNC is what you want. SSH is enabled by default on Raspbian and can be disabled using Raspi-config. SSH client is built into Linux distributions and Mac OS. For Windows system, the most popular SSH client is PuTTY (putty.exe).

To connect using PuTTY to your Raspberry Pi, you’ll need to know its IP address. This can be found from directly from the Pi if you have access to it or from the router if you are too lazy to move.

The default SSH port is 22
User name is: pi
Password: raspberry

Remote Raspberry Pi Access using VNC (graphical desktop)

VNC (Virtual Network Computing) is a graphical desktop sharing system that allows you to remotely control the desktop interface of a computer from another. You can use it to share just the graphic or transmit keyboard and mouse events as well, very similar to Windows’ Remote Desktop but very difference in the underlying protocol.

First, you’ll need to install a VNC package using a monitor or over SSH. The package that we recommend is TightVNC.

sudo apt-get install tightvncserver

Once installed, start a TightVNC Server.

sudo vncserver

It will prompt you to enter a password and an optional view-only password. Once the display is created, make a note of the raspberry:#. The # is the display number. Such as:

New 'X' desktop is raspberry:1

Now we’ll need to install a VNC client. For Linux machine, you can use the xtightvncviewer by

sudo apt-get install xtightvncviewer

For other OS such as Windows, go to http://www.tightvnc.com/download.php and download the viewer there.

Once installed, open the software and connect to your Raspberry Pi using its IP address followed by a ":" and the display number such as 192.168.1.10:1. Type in the password when asked and you should see a graphical desktop now.

You can specify the display number manually as well as other settings. Details can be found here: http://www.tightvnc.com/vncserver.1.php

To change the setting of a display, you’ll first have to stop the process by using:

sudo vncserver –kill :#

where # is the display number.

To start a new display #2 with 1920x1080 resolution and 24bit colour:

sudo vncserver :0 -geometry 1920x1080 -depth 24

Run VNC at boot

Log into a terminal on the Raspberry Pi using SSH or VNC and go to the following directory:

cd /etc/init.d/

Create a new file with the following script using an editor such as nano in /etc/init.d/

sudo nano vncboot

Copy or type in the following script:

#! /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
    sudo /usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565
    ;;

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

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

Crtl+X to finish editing. Yes to save and ENTER for saving at the current location. Afterward, make the new file executable:

sudo chmod 755 vncboot

while still in the /etc/init.d/ directory, make the file run at boot by enabling dependency-based boot sequencing:

sudo update-rc.d vncboot defaults

You should see this in response:

sudo update-rc.d: using dependency based boot sequencing

If you get an error unable to read error, go back to the root directory

cd /

and do this:

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

Reboot the Raspberry Pi and VNC should now auto load on boot.


Share this post



← Older Post Newer Post →


Leave a comment

Please note, comments must be approved before they are published.