RPi Remote Access

From eLinux.org
Revision as of 20:09, 7 July 2013 by Crazyskeggy (Talk | contribs)

Jump to: navigation, search

Back to Beginners Page

Remote Access to the Raspberry Pi

A default install of a Rpi will probably have an ssh daemon running. This means that the board is listening on port 22 for a remote host asking for a connection. You can run a command line, file transfer or GUI over a port 22 connection to the Rpi.

Initial Setup

Prior to your initial remote access it is recommended that you generate unique host public/private keys with the following command[1]

 sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server

You can execute these commands after having logged in remotely, and if executed while logged in from a remote client you will not be disconnected mid-session. However, after you generate unique you will need to clean up your client's known_hosts. [2]

This extra command (and subsequent follow up to update the cached public key on all clients who've already remotely connected to your Raspberry Pi) may seem like a hassle, but without doing this you leave yourself wide open to a man-in-the-middle attack because your "private" host ID keys are widely available to anyone who has downloaded the same SD card image as you.

Running a remote CLI

You need to have a SSH client program. Linux and Mac OS X already have this installed, for Windows get Putty or an alternative.

In order for this to work you must have port 22 open between you and the Pi. You must also have set up a user on the Raspberry PI to use. (see Beinners Guide or CLI page for how to do this).

Linux and Mac OS X

ssh <ip address of your Rpi> -l <username of RPi user you set up previously>

Here is a record of what happens with me

[brian@fc16toshiba ~]$ ssh -X  192.168.1.104 -l brian
The authenticity of host '192.168.1.104 (192.168.1.104)' can't be established.
RSA key fingerprint is 26:a4:a1:ab:c2:ff:50:99:d7:e1:49:6e:f2:90:fb:90.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.104' (RSA) to the list of known hosts.
brian@192.168.1.104's password: 
Linux raspberrypi 3.1.9+ #9 Mon Apr 9 20:50:36 BST 2012 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
brian@raspberrypi:~$


At this point you are running everything you type on the Rpi.

Windows (with Putty)

First you need to download Putty.

Create a Profile

I recommend to create a profile for your connection so you don't need to configure it every time you want to start it. Start Putty and type in the Host Name (or IP address) field the Raspberry PI's IP address (usually something like 192.168.0.xxx, use "ip address show"). If not already set, enter 22 as Port and select SSH as Protocol. Go to Connection -> Data and type your Raspberry PI's username under Auto-Login username. Now your profile is complete, you can save it under Session by typing a name for your profile under Saved Sessions and clicking on the Save button.

Establish a connection

To establish a connection to your Raspberry PI simply click on Open. If you can't etablish a connection make sure the SSH daemon is running on your Raspberry PI. For more information check the Advanced Setup.

Usually you will get a security warning, you can simply click on yes.

More information

Here is an excellent guide for setting up an SSH connection with Putty: http://www.howtoforge.com/ssh_key_based_logins_putty

Running a remote GUI

To do this, you need an X server on your machine. There is a free one available for Windows and Mac.

Two Xservers for Windows are Cygwin (which has a lot more besides) and XMing

For a Mac, either install Gimp for Lion 10.7 or earlier or install X11 from XQuartz

Linux has one built in.

The command uses the X switch to tell ssh to send the X commands to the X server on your host.

ssh -X <ip address of Rpi> -l <username on Rpi>

In case you are connecting from a Windows machine using Putty then you should enable X11 forwarding, this option can be found navigating the configuration tree through Connection/SSH/X11.

cannot open display: localhost:10.0

if RPi is left idle one needs to reboot to launch new applications that use X11. The ones already displayed work fine.

A fix and workarounds are of interest.

What is an Xserver?

A 'nix box running a GUI is almost certainly running "X" and also an X Server. The X sends commands to the X Server about what kind of things to put on the screen and the X server does it. This means that the GUI and the X server are separate. This also means that you can run a program on the Rpi and have all the graphical bit appear on the screen of the X Server somewhere else on the network. This removes a large amount of processor demand from the Rpi as well as meaning that you just need to plug the Rpi into your network and you need not plug in usb devices and hdmi as well.

Here is a record of what happens with me when I run the command. Log in and then run "midori" which is the browser on this Rpi. (The "&" means that the "midori" is launched as a separate process so you get your cli back).

[brian@fc16toshiba ~]$ ssh -X 192.168.1.104 -l brian
brian@192.168.1.104's password: 
Linux raspberrypi 3.1.9+ #9 Mon Apr 9 20:50:36 BST 2012 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed May 30 09:29:57 2012 from fc16toshiba.local
brian@raspberrypi:~$ midori &
[1] 5773

Sometimes you will get gtk errors which report library shortcomings on host (the Rpi) or server (Your X server) but the process is pretty robust.


Midori running in Remote Gnome 3 X Server

References

  1. [1] ryan29 on 20 Apr 2012 highlighted the reusage of private keys; accessed 7 Jul 2012
  2. http://www.cyberciti.biz/faq/howto-regenerate-openssh-host-keys, see step 3 - Accessed 6 Jul 2012