Install Raspbian and configure Wi-fi without a monitor or keyboard
I’ve just bought a Raspberry Pi and not having access to an extra monitor, keyboard or mouse I had to make do with just a router and an ethernet cable. I realize you could already piece most of this together from other places on the internet, but I wanted to document the way I did it. Having called a vote the motion passed with one in favor and none against so online it goes.
- First thing’s first and you’ll have to get a suitable image, I went with the Raspbian Wheezy and downloaded the torrent through Raspberry Pi Website Downloads. Be a pal and seed it for a while.
- Run
sha1sum 20XX-XX-XX-wheezy-raspbian.zip
and make sure it matches the one on the download page. - Run
unzip 20XX-XX-XX-wheezy-raspbian.zip
to extract the image. - Plug your SD card in and run
df -h
to find its name. In my case it was/dev/sdb
. - Unmount the right one with umount
/dev/XXX
. - Make sure you have the SD card name right and that you’ve unmounted it and run
sudo dd bs=4M if=20XX-XX-XX-wheezy-raspbian.img of=/dev/XXX
. This step might take a few minutes without any feedback so be patient. - Run
sudo sync
to ensure that everything in memory was written to the card, remove it, and plug it into your Raspberry Pi. - Get an ethernet cable with one of the ends plugged into a functioning router and plug the other end into the Raspberry Pi. Power on the Raspberry Pi with an adequate power source.
- After waiting for a minute go to your router page which in my case was http://192.168.1.254/. Find a page where you can check which devices are currently connected to the router and from that list get the IP that was assigned to the Raspberry Pi, it should be under the name “raspberrypi”.
- Run
ssh 192.168.0.XX -l pi
with the right IP address from the previous step. When prompted for the password, type in “raspberry”. - Run
sudo raspi-config
and select the update option. Mess around with other configurations as you please. Be careful with the overclocking and push “finish” when you’re done - After the Raspberry Pi reboots run
ssh 192.168.0.XX -l pi
again. - Update your package list with
sudo apt-get update && sudo apt-get upgrade
.
You now have a working installation running. If you wish to have a wireless internet connection there’s a couple more things you might want to do.
- Type sudo
nano /etc/network/interfaces
in and paste this into the file (Ctrl+Shift+V should work):
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
- To generate the right psk key run
wpa_passphrase yourssid yourpassword
. Typesudo nano /etc/wpa_supplicant/wpa_supplicant.conf
in and paste something like this into the file.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
eapol_version=2
ap_scan=1
fast_reauth=1
network={
ssid="SSID-OF-YOUR-WPA-PROTECTED-ACCESS-POINT"
proto=WPA
scan_ssid=1
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk=0f17de6096de525d59fb83ee0afa4de80846420a53dd8ea685325bef19e5e7c
priority=1
}
network={
ssid="SSID-OF-YOUR-WEP-PROTECTED-ACCESS-POINT"
scan_ssid=1
key_mgmt=NONE
wep_key0="PASSWD"
priority=2
}
- As an alternative, you might want to try and install a visual tool to connect to networks. Run
sudo apt-get install wicd-curses
and run it. It’s not as messy as configuration files and if you don’t know the quirks of each security setting it’s a lot easier. I’ve run into some problems with WEP on wicd-curses and that’s why I’ve opted to document the configuration files though. - After rebooting or running
sudo /etc/init.d/networking restart
you can unplug the ethernet cable and your Raspberry Pi should automatically connect to your router.
Now you could go into your router page and find which IP was assigned to the Raspberry Pi each time you want to connect or you could force it to choose a static IP. I chose a different option which was to use Avahi. Avahi makes the Raspberry Pi advertise itself to the network as “raspberrypi.local” so you can always use this alias to ssh into it, whatever IP it is assigned by the router. Pretty neat.
- Run
sudo apt-get install avahi-daemon
and thensudo insserv avahi-daemon
on the Pi. - Create a config file with sudo nano /etc/avahi/services/multiple.service` and paste in this.
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=RackMac</txt-record>
</service>
<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>
</service-group>
- Restart the daemon with
sudo /etc/init.d/avahi-daemon restart
and disconnect your ssh session. - You can now log into the Pi with
ssh [email protected]
or alternatively change the hostname to something more unique. - To change the hostname go to
sudo nano /etc/hostname
and insert whatever name you wish. Then on tosudo nano /etc/hosts
and replace “raspberrypi” with the name you chose earlier and finally runsudo /etc/init.d/hostname.sh start
to enable the changes.