1. Setting Up Remote Access

by HobbyGenius VIP on May 14, 2014 at 1:42 am | 0 comments.


Although the Raspberry Pi can be used as a computer, later down the line there’s no reason that you can’t use it as an embedded platform. Plug it in and leave it running somewhere secluded and it can do whatever you want it to. However the only problem is that there may come a time when you need to alter something on it. Instead of having to move the RPi to plug in a monitor, mouse and keyboard, we’re going to look at setting up means of accessing it remotely.

SSH

SSH is a protocol for connecting to computers that is best known for its use as in Unix-based systems (like Linux). It allows the user to send encrypted data over a network to an SSH server thus allowing them remote access. Most Linux distributions have SSH installed, including Raspian on the Raspberry Pi. Once the SSH server has started on a computer, another computer can use an SSH client to connect to it.

SSH Login

SSH Login

SSH is entirely text-based and is run from the terminal: it essentially allows the user connecting to a remote machine to use that machine’s terminal as if they were sat in front of it. We will start by looking at SSH access and then look at connecting to the Raspberry Pi’s Desktop to allow us a visual display.

What You Need

In order for your computer to remotely connect to your Raspberry Pi, it needs to be on the same network. Either device can be connected wirelessly or via an Ethernet cable to the router.

Ethernet Cable

Ethernet Cable

Unless you know what you’re doing we recommend you don’t enable access to your Raspberry Pi from anywhere outside of your local network. It can be very easy to add a backdoor to your network if you don’t know what you’re doing.

However, that doesn’t mean your RPi cannot connect to the internet like any other computer (and all of our tutorials will assume that you have done this).

Get Your IP Address

In order to connect to our Raspberry Pi, we are going to need to know its IP Address on the Local Area Network (LAN). In the terminal, type in ifconfig and the RPi’s network information will be displayed.

Network Info

Network Info

The IP Address will be displayed after inet addr (as shown above). This will be the IP Address that we use to connect with using our other computer.

SSH Configuration

Terminal

Terminal

First we need to start by enabling SSH on the Raspberry Pi. Before we can start connecting remotely, we need to set some things up on the RPi. Start by opening up the terminal and type in sudo raspi-config

Raspi-config

Raspi-config

Navigate down to ssh with the arrow keys and hit the enter key. Select Enable and hit enter again. You should now receive message saying SSH has been enabled.

Create a Password

When we originally set up Raspian, we suggested that you change the default password if you plan on networking your Raspberry Pi. If you have already done this then you can skip to the next step, but if not then we strongly recommend you create a new password.

change_pass

change_pass

Whilst in the Raspian configuration window, select change_pass from the menu; you will then be prompted to enter a new password.

SSH Client

Now that our Raspberry is setup for SSH access, we need to install a client on another computer which will connect to it. There are several clients available for SSH access and you are welcome to use which ever you like. If you are using windows then we recommend you use PuTTY. If you are using Linux or Mac OS X, you can simply open up the terminal and type in ssh followed by your parameters (we’ll get to these soon).

Connecting with PuTTY

PuTTY

PuTTY

First open up PuTTY and you will be presented with an options screen:

PuTTY Configuration

PuTTY Configuration

Select SSH from the Connection type and type in your IP address in the Host Name (port 22 should automatically be selected as this is the default SSH Port), then click Open.

SSH Login

SSH Login

Enter pi as your username (unless you have different login information) and then type your password.

If you are presented with a notice about the authenticity, just type yes and the notice will disappear. We can ignore this since we are only connecting across a local network. If you wanted to set up SSH for a wide area network, you would have to add more security but we won’t be going into that.

SSH Terminal

SSH Terminal

You have successfully connected to your Raspberry Pi via SSH. You can now navigate around your RPi as if you were using its terminal.

Connecting with Mac OS X

Open up the Mac Terminal (this can be found in the Utilities folder of Applications), and type in ssh pi@ipaddress where ipaddress is the IP Address of your Raspberry Pi. If you wish to login as a different user simply replace pi with your selected username.

SSH Terminal

SSH Terminal

Enter yes if you are presented with a notice about the authenticity of the host and then enter your password. We can ignore this since we are only connecting across a local network. If you wanted to set up SSH for a wide area network, you would have to add more security but we won’t be going into that.

SSH

SSH Terminal

Once successful you can navigate around your RPi as if you were using its terminal.

Remote Desktop

In order to connect to our Raspberry Pi’s Desktop we must first install some software on the RPi and then download client software for other computers.

Remote Desktop

Remote Desktop

Installing VNC Server

First open up your Raspberry Pi and ensure it is connected to the internet and that SSH is enabled (as detailed in the steps above).

Open up the terminal and type in sudo apt-get install tightvncserver

tightvncserver

tightvncserver

Apt-get is a program on our Raspberry Pi that connects to an online repository of software. We want to install the software called TightVNCServer. After you hit enter, the program will find our software and ask if we want to install it; type y and hit enter until the program downloads and installs.

Installing TightVNCServer

Installing TightVNCServer

Once complete we can type in tightvncserver and it will run for the first time:

Enter a password

Enter a password

For added security you should enter a password here and this will be required when people try to connect. Type when prompted for a view-only password and you server will start.

A view-only password is another password for users who just want to observe rather than control the RPi.

TightVNCServer

TightVNCServer

Starting VNC Server on Login

Now that we have our VNC Server installed we need to ensure it starts automatically when we turn the Raspberry Pi on; otherwise we’d have to start it manually which defeats the point of having it placed somewhere out of the way without a screen, mouse and keyboard.

Getting a program to start automatically when a user logs in is very simple on Raspian (especially compared to other Linux distros).

We want to place a .desktop file in the autostart folder of the user’s configuration. Open up terminal and type in mkdir /home/pi/.config/autostart

Create the Autostart directory

Create the Autostart directory

This will create a new directory in the .config folder of our user (pi). The autostart folder doesn’t exist by default but if it does you will presented with an error message saying that it does exist.

Next navigate to our folder by typing cd /home/pi/.config/autostart and then we want to create a new file called vnc.desktop. We can do this by typing nano vnc.desktop

Create a New.desktop File

Create a New .desktop File

Nano is an easy to use Linux text editor that is built into Raspian. The command nano will open the specified file and if it doesn’t exist then it will create it. In this case, the file vnc.desktop doesn’t exist but this same command later on will let you edit the file again.

In our .desktop file we want to execute the command tightvncserver :1 which will start a new vnc server on port 1

vnc.desktop

vnc.desktop

Type in:

[Desktop Entry]
Name=TightVNC
Exec=tightvncserver :1
Type=Application
Terminal=False

You must ensure there is a space between tightvncserver and :1 otherwise the command will return an error.

Press CTRL-X to exit nano and when prompted, type y to save the file.

Testing

We can now restart the Raspberry Pi and see if our server has started.

Reboot Your Raspberry Pi

Reboot Your Raspberry Pi

Once your RPi has loaded again, open up the terminal and type in tightvncserver :1 (the command we told the computer to run on start-up).

TightVNCServer

TightVNCServer

If all goes well you should be presented with an error saying the VNC server is already running. You can plug your Raspberry Pi in somewhere secluded and as long as it has a connection to your network then you will be able to remotely control it.

VNC Client

Now that we have a running VNC Server on our Raspberry Pi, we need software for our other computers to allow us to access the Desktop. We will be using RealVNC since it is very easy to use and can work on many platforms.

Download VNC Viewer

Download VNC Viewer

Head over to the VNC Viewer download page and select the program appropriate to your Operating System.

We will now demonstrate how to use VNC Viewer on Mac OS X however it is identical in Windows.

VNC Viewer

VNC Viewer

Once open simply type your Raspberry Pi’s operating system followed by :1 (for the server on port 1 as we specified earlier) and click Connect.

Note that you can also type the computer’s name instead of the IP Address, by default Raspian gives your Raspberry Pi the name raspberrypi so typing raspberrypi:1 would also work (unless of course you have changed it).

You will be given a notice to say that your connection won’t be encrypted but simply ignore this since we are only connecting across a local network.

Unencrypted Connection

Unencrypted Connection

Finally you will be prompted for the password that you set when you installed tightvncserver (as shown above).

Enter Your Password

Enter Your Password

Enter your password and if all goes well you should be able to connect to the Raspberry Pi’s Desktop.

Remote Desktop

Remote Desktop