[Elektronik] Raspberry Pi

To make this thread accessible by more readers I decided to write this in English.

A couple of weeks ago I ordered a Raspberry Pi mainly just for playing around a bit. Since I’m not a Linux user, finding and setting up my perfect setup was kind of challenging. But due to a rather huge RPi community I managed to get a lot done and even learned some Linux basics I guess. I want to present my setup here, with all the how-tos and guides, which helped me to get there. I will skip explaining the RPi since there are tons of good websites doing this exactly.

Formatting SD card
Nano editor
SSH connect
SSH, bootscript and security issues
Connect with Android
Coming soon

Since I am somehow completely new to Linux, don’t rely on this instructions only. When it comes down to security issues, always triple check what to do. I won’t take charge, if something goes wrong. back

I ordered my RPi  from www.getgoods.de including:
Raspberry Pi Model B Rev 2.0
Samsung 16GB Class 6 SDHC Card
HDMI 1.4 cable
RPi case
TP-Link TL-WN725N Wi-Fi Dongle / CSL Wi-Fi Dongle

The RPi, an SDHC card and a PSU are mandatory. You can somehow set up the RPi headless, which I didn’t do and which isn’t covered in this tutorial, so I needed a HDMI cable. The PSU can be any µUSB PSU with more then 1A.

Unfotunately the TL-WN725N comes in two different version. v1 works out of the box, where for v2 one need to install the drivers manually. Of course I got v2 and despite some tutorials, I wasn’t able to get the dongle running. I ordered a CSL Dongle from amazon, which works out of the box without an additional active USB hub.

You can have a look here for compatible dongles  or you substitute the dongle by an ethernet cable to dodge all compatibility problems.

For setting up the RPi you’ll also need a keyboard, preferably a mouse and a laptop or a PC with an SDHC card reader.

Since I still have trouble with the CEC for OpenELEC I have a rapoo wireless keyboard connected to the second USB port. If someone who knows how to set up CEC (or knows how to check wether my TV supports CEC or not) reads this, please drop a comment. back

Formatting SD card
You can use SD Formatter v4 for Windows. Put the SD card in your laptop or card reader, start the tool and select quick format and format size adjustment yes. back

Berryboot is a multiboot program for the RPi. Multibooting is the alternative to switching SD cards every time you want the RPi boot to a different OS. Just download the file and extract it to the formatted SD card. Then put the card in your RPi, connect ethernet, keyboard, monitor and finally the PSU. You should see the Berryboot menu coming up where you can now select the OS you want to install. This tutorial covers only OpenELEC and Wheezy. After installing the OSs (see below) I made openELEC my default and set bootmenutimeout to 3 (Advanced configuration  -> cmdline.txt -> bootmenutimeout=3). back

Nano editor
This is the editor we will use to create and modify files. It comes with Wheezy and doesn’t need to be installed. To create/modify a file type nano filename. You can navigate with the arrow keys, paste from clipboard with rightclick, save with F3 and exit with F2. That’s all you need to know for this guide. back

openELEC is a slim but powerful multimedia center for your TV. After installing it via berryboot I recommend to update to the latest version via ethernet cable and GUI since connecting via Wi-Fi could cause problems in the installed version (at least for me it did). After updating connecting via Wi-Fi should work easily. back

Wheezy is another OS for the RPi, which we need to install all the following servers.
expand_rootfs = yes
overscan = depends on wether you see the green lines or not
configure_keyboard = since there is no entry for my rapoo wireless, I didn't change it
change_pass = no need to change the pw for pi here, since we will delete this user later on for security reasons
change_locale = not changed
change_timezone = change to your timezone
memory_split = not changed
ssh = enable

I recommend booting Wheezy to desktop for the first time since you can configure Wi-Fi connection more easily (at least I could). Just double click on Wi-Fi Configuration and enter your Wi-Fi’s SSID and stuff. After the configuration open a terminal and type raspi-config to disable boot to desktop and reboot. back

ssh connect
From now on, nearly everything can be done headless via ssh. I just use putty, which is really easy to handle. First you find out your RPis IP adress by typing ifconfig. Then you connect via putty with pi@x.x.x.x at port 22 and ssh. back

bootscript, ssh and security issues
Now we will set up the RPi so that you can control it safely via internet. First of all, we will rename the standard pi user. Actually we won’t rename it but rather copy and then delete it. Just follow these instructions. Remember that you will have to do all the following for your new user, let’s name it john, instead of the standard user pi.

Next thing is to write a little script for switching between OSs via ssh. For rebooting to your default OS just type sudo reboot on Wheezy and reboot on openElec (since there is only the superuser). For rebooting to your non default OS, Wheezy in this case, we do the following:
On Wheezy:
Create a directory with mkdir mnt
Create a script file with sudo nano reboot2
Enter the following:
sudo mount /dev/mmcblk0p2 /mnt
sudo su
echo "Debian_Wheezy_Raspbian_2013.05.img192" > /mnt/data/runonce
echo "Booting to Wheezy"
sudo reboot

Make the script executable with chmod +x reboot2
Copy your script with cp reboot2 /usr/bin
You can now reboot to Wheezy by typing reboot2
On openELEC you do exactly the same, but the reboot2 file should look like this:
mount /dev/mmcblk0p2 /mnt
echo "Debian_Wheezy_Raspbian_2013.05.img192" > /mnt/data/runonce
echo "Booting to Wheezy"

This is a combination of this and that tutorial.

Next thing we want to do is to switch away from port 22 for ssh. Therefore we have to edit sshd_config. On Wheezy we additionally forbid root login via ssh. We shouldn’t do that on openELEC though, since there is only the root.
sudo nano /etc/ssh/sshd_config
Change Port 22 to e.g. Port 1337
Set PermitRootLogin to no
Restart ssh via sudo /etc/init.d/ssh restart
nano /etc/sshd_config
Change Port 22to e.g. Port 1337
reboot Remember to change the port on putty as well.

The last security related change is to deactivate password login after having created an ssh key pair. You generate the pair of keys on your Windows machine using puttygen. Then you write the public part on your RPi using
cd ~
mkdir .ssh
cd .ssh
sudo nano authorized_keys

Paste from clipboard, save, exit.
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys

The private key has to be used in putty in Connection-SSH-Auth-Browse…
Test your key, if it works, disable password login using
sudo nano /etc/ssh/sshd_config
Change PasswordAuthentication to no
sudo /etc/init.d/ssh/ restart
On openELEC you can just disable password login via the GUI.
A more detailed version can be read here and here.

From now on your RPi should run safely online. All of the following steps are for Wheezy only. None of them will work on openELEC. back

Just follow this (german) or that (english) guide step by step. back

Follow this guide from “Installing the server” step by step but leave out the finishing touches, since changing your home directory will cause your key authentication to fail. I used the Apache version. back

Just follow the seafile section of this guide. back

Just follow the instructions on this website. I installed the fast version since the updated one can take up to nine hours. back

To make your RPi accessible from the internet you need to forward the following ports: (For an instruction on how to forward ports please read your routers user’s manual. Usually you browse to your local IP x.x.x.1, login and continue by using your browsers GUI.)

Function Port Type
ssh 1337 TCP/UDP
mumble 64738 TCP/UDP
seafile 10001 TCP
seafile 12001 TCP
seafile 8082 TCP
seafile 8000 TCP

The last thing we want to do is assign a URL to the RPi. First check you IP here. Then register here and choose a subdomain which you then assign to your IP. Now you can browse your website hosted by your web server simply by typing yourname.yoursubdomain.com into your browser. You can now login to your RPi from the internet via ssh by typing john@yourname.yoursubdomain.com. Make sure you have your private key at hand and changed the ssh port in putty. back

Connect with Android
The most advanced, free app for ssh is JuiceSSH.The only thing you have to do is load your public key with puttygen, convert it to OpenSSH and copy it to your android phone. The JuiceSSH’s smart search should find the key automatically. back

Coming soon
Since there is no use of running a cloud service on a 16GB card, I want to add an external HDD to my setup. Therefore I ordered an active USB hub and an USB to µUSB cable from ThePieHut. The package is on its way. back