Enabling remote SSH on Raspbian (Raspberry Pi)

I’m off to visit some family this weekend and I’d like to be able to use my Raspberry Pi while I’m away, so this will involve setting up SSH and making it visible remotely (outside my home network). I’d like to access it from my Android phone.

Enable SSH on Raspbian

Firstly install the SSH service by running this command:

sudo apt-get install ssh

Then start the service:

sudo /etc/init.d/ssh start

And now we want to make it start every time the Pi boots:

sudo update-rc.d ssh defaults

Next up, try a reboot and confirm everything works. Reboot by running sudo reboot.

Connecting to the Pi over SSH

To connect, you’ll need to know the IP address of your Pi. You can get that by typing sudo ifconfig. There will be a line starting “inet addr: …”, and the IP address is next to that.

I have connected to the Pi from my windows machine using PuTTY. Download here. Once you’ve got PuTTY installed, put it in a sensible location on your hard drive and open it. Fill in your Pi’s IP address, and in the Saved Sessions section, type “Raspberry Pi”. Click Save.

 You should be able to click Open and log in.

For convenience, I created a shortcut on my desktop that would open the session directly. Right click your desktop, and click Create Shortcut. Browse to putty.exe and create it. Then right click on the shortcut and go to Properties. Change the Target to this:

"C:\path\to\putty.exe" -load "Raspberry Pi"

 SSH from your Android phone

I installed a great app called ConnectBot. I tried a couple and this was the best. It’s open source and doesn’t have any ads. When you open it, just type in the address in the format “pi@:192.168.0.9“. It’ll prompt you for your password.

Allow access from the internet

OK, I don’t recommend this. Everything up to now is in your own home network and is pretty much a walled garden, safe from bad people. Once you allow access from the internet, you’re potentially opening yourself up to hackers and I don’t have the knowledge to give proper security advice.

That said, I do know the first step is to change your password. Use the command passwd.

Next you need to open port 22 on your router, and set it to forward to your Raspberry Pi. This means that requests from the internet on that port will automatically go to the right place. On my Sky router the set up looks like this:

Next you will want to set the IP address of your Pi to be static, so that it doesn’t change when you reboot. In your router interface, check the list of attached devices and note your Pi’s MAC address:

Then add an entry to the list of reserved IP addresses:

Now you should be able to SSH into your Pi from your laptop (using PuTTY) or phone (using ConnectBot) and instead of entering the 192.168.0.x address, you can use your public broadband IP address.

Finally, if you don’t have a public static IP address (in other words, your ISP keeps changing your IP address) then how do you know what it is? You need to set up a DNS service on your Pi that will regularly check what the network public IP address is, and keep a domain name up to date. Then you can connect using a domain name instead of an IP and it’ll automatically resolve to the correct IP. There are lots of ways to do this – click here for some ideas.

Raspberry Pi media PC with XBMC


What to do with a £30 computer? I’ll get to writing some code for this thing after Christmas. For now, it’ll make a nice media PC. Here are all the details of what I went through to get this up and running.

You will need

  • Raspberry Pi
  • Power supply – a micro USB adapter (my samsung phone charger worked fine). Needs to be 5v and at least 700mA.
  • SD memory card. Make it 2GB or more. I bought this one.
  • USB keyboard (not strictly needed but it’ll be handy now and again)
  • Ethernet connection

Operating System

You could use Raspbian, OpenELEC or Raspbmc. They’re all Linux based and any one would do. Raspbian is the standard OS for the Pi, OpenELEC and Raspbmc will make running XBMC (XBox Media Center) easy. I went for Raspbmc. They’re all super easy to install. For Raspbmc, go here for the download. It just involves sticking the SD card into your laptop and running an installer to get the OS on to the card. Stick the card into your Pi, connect everything up, and voila.

It all seemed to work perfectly for me but keyboard input stopped working after about a minute, every time, and needed a reboot. This would be followed a few minutes later with the power going off. Now, if something goes wrong, and it will, you’ll need to start a trial and error process to narrow down what’s wrong. The Raspberry Pi forums are a great source of help and helped me realise that my power supply was dodgy. This quote sums it up:

This is often due to either (or both) a bad power supply (power supplied much below advertised one), power cable (someone compared a lot of them to wet rope, not ideal for conducting electricity), keyboard (some have power requirements much higher than the 100mA the Pi can supply, this is never listed in their specs, and can vary by production batch for off-brands), or mouse (ditto).

I switched it with my wife’s phone charger which worked perfectly (mine was from ebay – may have something to do with it). Trial and error is the key.

Next problem: audio didn’t work via the HDMI cable into my TV. Cue a change to the Raspberry Pi’s configuration file. This is a text file in the root of your SD card called config.txt containing a list of key-value pairs for configuring various options. I fixed my audio problem with a clue from this forum thread – adding these options to the config.txt:

config_hdmi_boost=4
hdmi_drive=2

Check this page for an explanation of those config options. I probably only needed the hdmi_drive option but I’m too lazy to test them individually.

Spot the Pi. Maybe a case is in order…

Now to remote control. You can use a lot of “one-for-all” type remotes, I wanted to use my phone. The official XBMC Remote doesn’t work with the latest XBMC (!) as the HTTP API has been deprecated and removed. Luckily, there are lots of better options available on the Android (and iOS) app stores. I used Yatse. Yatse is VERY slick – it detects the XBMC instance on your home network quickly and is easy to use.

Next up, BBC iPlayer and ITV player. There are lots of others available. The iPlayer app is actually better than the official one on my Blu-ray player as it gives live streaming too. To get it from your computer to the Pi, you need to create a shared folder that the Pi can see. I shared C:\xbmc with a new user called xbmc. You could just be lazy and share it with the ‘Everyone’ group. Copy the zip files in there. Next, in XBMC, go to System -> Settings -> Add-ons -> Install from zip file. Select your share from the list (you will need to create it there first and tell it to look at the C:\xbmc folder you created) and select the correct zip file. Then go back to the home screen and select Videos -> Add-ons. There they are!

Pi Store ideas

That’s XBMC up and running. It’s nice to have it up and running, but I imagine I’ll want to start tinkering with the Pi again. I’ll leave you with some ideas for development. Maybe some day these type of apps will end up on the brand new Pi Store!

Web server/downloader:

  • For an electricity worth about £4 a year the Pi is almost cost-free to run 24/7. It could be downloading all your stuff. It would be sweet to have a web interface where you could queue URLs or torrents or whatever and the Pi will download them whenever your connection isn’t busy.

Games:

  • It’d be nice to use smart phones as input devices for a game server running on a Pi and the TV. Like a multiplayer skiing game where the phone accelerometer allows you to steer.

Ideas for media pc/backup:

  • Use the Pi for backup. There’s an 8GB memory card which will be more than enough to back up documents at least. For a hardcore backup option, connect a USB hard drive to it.
  • Have a task running on the laptop which copies photos from My Pictures across to the Pi’s pictures folder.
  • App for our Android devices to automatically back up everything to the Pi on a regular basis while on the home WiFi network. Photos will then be browsable.
  • App for the Pi to backup everything on it to cloud storage.

Home automation:

  • Thermostat control. Wire in a tempertature sensor, use a relay for switching. Add a web server and a web app to allow remote access. I’m obsessive about the temperature in my house, so I would be able to chart it all.

Vegetarianism

Our health visitor today expressed surprise that our 9 month old baby has not eaten meat yet and suggested we speak to a dietitian. Which got me thinking about this topic.

When I’m out and about and eating food in public (eg. Christmas dinner!) Once thing that I will invariably be asked is why I’m vegetarian*. A reasonable question given the normal vegetarian choice in restaurants. Pasta isn’t too festive and nut roast couldn’t have a worse reputation.

The question is usually appended with a follow up like “is it an animal rights thing?” Well, no, although that may well be a valid reason.

My answer is to reverse the question: why do you eat meat? The only answer, the answer that all others derive from, is that we’ve all been brought up in a society where it’s normal. You eat meat because your parents taught you to, and because in society, we’re inundated with meat based foodstuffs. You’ve now developed a taste for chicken korma or slow cooked ribs or pepperoni pizza or rare steak** and that’s hard to let go of. Why should you? But it’s circular, and seems like a pretty lame reason to me.

After having been vegetarian for around 7 years I now can’t see any attraction in eating meat. I eat a much more balanced diet now than I used to, with a greater range of flavours. I’ve come to realise that the bulk of meat dishes taste of whatever you cook them in (chicken anyone?). And the idea of slaughtering an animal doesn’t seem worth it.

Tasty beef

Please don’t eat me

Don’t start me on the nutrition thing – a few hundred years ago, or maybe even 30 years ago (I wouldn’t remember), chicken would have been an important source of protein. We didn’t have the huge food supply we have today, and there weren’t 30 aisles in Tesco where you could get a vast selection of nuts and pulses, soya, and quorn, if that’s your thing. And if you’re among the large portion of people whose meat intake consists largely of cocktail sausages, chicken nuggets or fast food burgers, then….well, y’know.

So now that we know the bad reasons why you eat meat, here are some good reasons why you might want to be vegetarian.

Firstly, the well known health benefits as summarised here by the US Department of Agriculture “Dietary Guidelines for Americans“:

In prospective studies of adults, compared to non-vegetarian eating patterns, vegetarian-style eating patterns have been associated with improved health outcomes—lower levels of obesity, a reduced risk of cardiovascular disease, and lower total mortality. Several clinical trials have documented that vegetarian eating patterns lower blood pressure. On average, vegetarians consume a lower proportion of calories from fat (particularly saturated fatty acids); fewer overall calories; and more fiber, potassium, and vitamin C than do non-vegetarians. Vegetarians generally have a lower body mass index. These characteristics and other lifestyle factors associated with a vegetarian diet may contribute to the positive health outcomes that have been identified among vegetarians.

Environmental impact is another good reason:

Pachauri, who was re-elected the [United Nations Intergovernmental Panel on Climate Change]‘s chairman for a second six-year term last week, said diet change was important because of the huge greenhouse gas emissions and other environmental problems – including habitat destruction – associated with rearing cattle and other animals. It was relatively easy to change eating habits compared to changing means of transport, he said.

So now you know.

*I’m not really vegetarian, because I occasionally eat fresh, oily fish. Extremely good for you.
**if you like your steak cooked “well done”, you are a bad person.