This guide walks you through how to set up your Raspberry Pi without connecting a TV or computer monitor to it at all only by the means of using an ssh tunnel and a computer. This guide is tailored for using Ubuntu linux, however other operating systems can do the same in a slightly different way.
This method can be very useful for those who do not have access to a HDMI TV or computer monitor where they could do the initial configuration for their Raspberry Pi.
This guide is based on using Raspbian Wheezy OS version 2013-12-20.
Installing on an SD Card
The steps are described at elinux.org nicely, however I would like to point out a few things here.- Obtain a copy of the latest (or desired) version of raspbian.img from
http://downloads.raspberrypi.org/raspbian/images/
In this article I will be referring to 2013-12-20-wheezy-raspbian.zip - wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-12-20/2013-12-20-wheezy-raspbian.zip
- unzip 2013-12-20-wheezy-raspbian.zip
- Note: for me the SDcard was /dev/sdb. You can check yours by e.g. running gparted with
sudo gparted
and checking the devices. Makes absolutely sure you are using the correct one! - WARNING! The command "dd" will be used here that can cause major data loss if used incorrectly. "of=/dev/sdb" must be correctly given as output destination. If you choose the wrong drive, it may overwrite everything on your computer's hard disk. In my case the command was
sudo dd bs=1M if=2013-12-20-wheezy-raspbian.img of=/dev/sdb
dd -calls dd file copying formatting tool
bs=1M - Tells what block size to use. This is important!
if=xxx - Input file
of=xxx - Output file (again where the command will write) - Flush write cache with
sudo sync
WARNING!
When using "dd" please make sure what you are doing. Selecting an incorrect device will lead to data loss.
Note that I have used the second latest Raspbian image as I had issues with the 2014 version with libc6, so I have decided to downgrade. You may try the latest version of course.
At this point you should be done and read to boot your Raspberry Pi for the first time. However, I would like to show how you can set up internet access right away without the need to connect the Pi to a screen. This will allow you to ssh into the device at first boot and configure from there.
sudo mkdir -p /mnt/raspberry
sudo mount /dev/sdb2 /mnt/raspberry
Open the network configuration file with
sudo nano /mnt/raspberry/etc/network/interfaces
And make it look similar to this
Save file with CTRL+O and exit with CTRL+X.
Explanation
These settings give a static local IP address to your Pi both to the ethernet (cable/wired) and wireless interface. A static address is useful as this will let you connect to the device always with the same IP address instead of having to search for it on the local network. If you have your Pi connected to your home router with a cable and do not use WiFi, then you don't need to configure the WiFi configuration part.
Assuming you have WPA2-PSK WiFi encryption the wpa-ssid and wpa-psk fields are correct and should be filled in with your network's credentials [2]. If you have other type of WiFi encryption on your local network, please refer to https://wiki.debian.org/WiFi/HowToUse to find the correct settings.
Of course, if your home network is different then you have to adjust the appropriate fields. The above settings are just a sample that you can use.
You are done with the most important configuration part, now the SD card can be inserted into the Pi and booted for the first time. Remove the card from your computer with
sudo sync
sudo umount /mnt/raspberry
Remove SD card and plug it into the Pi.
Configuring Internet Access
This part depends on whether you want ethernet or wifi internet access. First, mount the newly formatted SD card's 2'nd partition, sdb2 in my case, sosudo mkdir -p /mnt/raspberry
sudo mount /dev/sdb2 /mnt/raspberry
Open the network configuration file with
sudo nano /mnt/raspberry/etc/network/interfaces
And make it look similar to this
auto lo
#Wired interface, ethernet connection
iface lo inet loopback
iface eth0 inet static
#address 192.168.0.25
#netmask 255.255.255.0
#gateway 192.168.0.1
#Wireless interface (Wi-Pi)
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.25
netmask 255.255.255.0
gateway 192.168.0.1
wpa-ssid YOURWIFISSID
wpa-psk YOURWIFIPASSWORD
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Save file with CTRL+O and exit with CTRL+X.
Explanation
These settings give a static local IP address to your Pi both to the ethernet (cable/wired) and wireless interface. A static address is useful as this will let you connect to the device always with the same IP address instead of having to search for it on the local network. If you have your Pi connected to your home router with a cable and do not use WiFi, then you don't need to configure the WiFi configuration part.
Assuming you have WPA2-PSK WiFi encryption the wpa-ssid and wpa-psk fields are correct and should be filled in with your network's credentials [2]. If you have other type of WiFi encryption on your local network, please refer to https://wiki.debian.org/WiFi/HowToUse to find the correct settings.
Of course, if your home network is different then you have to adjust the appropriate fields. The above settings are just a sample that you can use.
You are done with the most important configuration part, now the SD card can be inserted into the Pi and booted for the first time. Remove the card from your computer with
sudo sync
sudo umount /mnt/raspberry
Remove SD card and plug it into the Pi.
First Boot
If you did everything correctly, your Raspberry should boot without a problem. Wait about a minute before you would try to ssh. Then you can
ssh pi@192.168.0.25
(192.168.0.25 based on the interfaces configuration file I posted above)
Now you are presented with the terminal login. Log in with the default username and password:
username: pi
password: raspberry
The first thing you probably want to do is open raspberry config and do a few things. You can do this over an ssh tunnel with
sudo raspi-config
Based on what you want to do with your raspberry you can set up a range of things. What I have set up for mine:
ssh pi@192.168.0.25
(192.168.0.25 based on the interfaces configuration file I posted above)
Now you are presented with the terminal login. Log in with the default username and password:
username: pi
password: raspberry
The first thing you probably want to do is open raspberry config and do a few things. You can do this over an ssh tunnel with
sudo raspi-config
Raspi-config screen over an ssh tunnel |
Based on what you want to do with your raspberry you can set up a range of things. What I have set up for mine:
- Set custom hostname
- Set GPU memory allocation to 16 as I will use the device without GUI and therefore won't need much RAM for the GPU
- Expand partition (The image file copied to the SDcard is sized for smaller 2-4 GB card. So if your card is bigger, you should expand the partition on it to make it usable)
Add a new user instead of the default pi with
sudo adduser YOURUSERNAME
Give the password twice and fill out the additional information. Then give root permissions to this user by editing the following file
sudo nano /etc/sudoers
And look at the end of the file and append the line
#includedir /etc/sudoers.d
pi ALL=(ALL) NOPASSWD: ALL
YOURUSERNAME ALL=(ALL) NOPASSWD: ALL
This pretty much sums up the most important steps you should take when installing new a Raspberry Pi. The rest is up to you what you want to do with your device.
I like this method, because it spares me the hassle of connecting my Raspberry to a TV, attaching keyboard etc. to configure it. I also keep a second SD card installed as a backup that is just a clean install with ssh access. I had problems before with file system corruption and a quick SD card swap has saved a lot fo problems for me.
References
[1] - http://elinux.org/RPi_Easy_SD_Card_Setup[2] - https://wiki.debian.org/WiFi/HowToUse