Setup Rasbian
Rasbian is a version of Debian for the RaspberryPi.
This tutorial assumes that you are using a Unix system.
If you are having trouble while installing rasbian, you can use the official tutorial.
Download the last version of raspbian
You need to get the last version of rasbian from the
The rasbian stretch lite version is recommended since we are not going to use the desktop environment.
If the link does not work, you can search for the correct .zip file in this page.
Install on the SD card
Connect the SD card
You first need to connect the SD card to your computer.
Use lsblk to get the name of the device on your computer.
The device path has the following format: /dev/sdX where X is the letter of your device.
For example:
silvanosky@GLaDOS_M ~ % lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 35G 0 part /
└─sda4 8:4 0 172.3G 0 part /home
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 43.2M 0 part /media/boot
└─sdb2 8:18 1 14.8G 0 part /media/rootfs
The path to the sdcard in the example is /dev/sdb.
Unmount the SD card
If a tool automatically mounted your SD card partitionsm you need to unmount them first.
Using umount /dev/sdX1 replacinf X by the letter of your device and for each of the partition numbers (1, 2, etc).
Using the previous example:
silvanosky@GLaDOS_M ~ % sudo umount /dev/sdb1
silvanosky@GLaDOS_M ~ % sudo umount /dev/sdb2
silvanosky@GLaDOS_M ~ % lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 35G 0 part /
└─sda4 8:4 0 172.3G 0 part /home
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 43.2M 0 part
└─sdb2 8:18 1 14.8G 0 part
Each partition is now unmounted and we can safely write on the SD card.
Write the Raspbian image to the SD card
You previously downloaded the .zip file containing the OS from raspberry.org.
You need to unzip the file to get the image file.
For example, if your file is located in ~/Downloads/:
silvanosky@GLaDOS_M ~ % cd Downloads
silvanosky@GLaDOS_M Downloads % unzip 2018-06-27-raspbian-stretch-lite.zip
Archive: 2018-06-27-raspbian-stretch-lite.zip
inflating: 2018-06-27-raspbian-stretch-lite.img
You will get a .img file. This is the image file.
Then you need to use dd to write the image to the SD card (replace *FILENAME* with the name of yout .img file and replace X with the letter of your device):
sudo dd bs=4M status=progress if=./*FILENAME*.img of=/dev/sdX
For example:
silvanosky@GLaDOS_M Downloads % sudo dd bs=4M status=progress if=./2018-06-27-raspbian-stretch-lite.img of=/dev/sdb
1862270976 bytes (1.9 GB, 1.7 GiB) copied, 44 s, 42.1 MB/s
444+0 records in
444+0 records out
1862270976 bytes (1.9 GB, 1.7 GiB) copied, 134.768 s, 13.8 MB/s
silvanosky@GLaDOS_M Downloads % lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 35G 0 part /
└─sda4 8:4 0 172.3G 0 part /home
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 43.2M 0 part
└─sdb2 8:18 1 1.7G 0 part
You now have a Rasbian system on your SD card.
Control the RaspberryPi
Before starting up the RaspberryPi we need to setup the ssh access on it.
This method is headless(it does not use a screen or a keyboard on the raspberry pi).
Activate the SSH
To activate the ssh on the RaspberryPi we need to create an empty file on the boot partition. We first need to mount this partition. Replace X with you device:
sudo mkdir /mnt/boot
sudo mount /dev/sdX1 /mnt/boot
For example:
silvanosky@GLaDOS_M Downloads % sudo mkdir /mnt/boot
silvanosky@GLaDOS_M Downloads % sudo mount /dev/sdb1 /mnt/boot
silvanosky@GLaDOS_M Downloads % lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 35G 0 part /
└─sda4 8:4 0 172.3G 0 part /home
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 43.2M 0 part /mnt/boot
└─sdb2 8:18 1 1.7G 0 part
Then you can create the empty file in /mnt/boot/:
sudo touch /mnt/boot/ssh
Network configuration (optional)
In case you cannot connect the raspberry pi to a router with dhcp (automatic ip address allocation) or if you want to know the ip address of the raspberry pi without using a screen, you need to set up a static ip address.
The easiest way to do that is by setting up a fallback profile on the RasberryPi. That means that if the raspberry pi does not find a DHCP server, it will use a default ip address.
To access the configuration files you need to mount the root partition of the SD card. Replace X with your device:
sudo mkdir /mnt/root
sudo mount /dev/sdX2 /mnt/root
For example:
silvanosky@GLaDOS_M Downloads % sudo mkdir /mnt/root
silvanosky@GLaDOS_M Downloads % sudo mount /dev/sdb2 /mnt/root
silvanosky@GLaDOS_M Downloads % lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 35G 0 part /
└─sda4 8:4 0 172.3G 0 part /home
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 43.2M 0 part /mnt/boot
└─sdb2 8:18 1 1.7G 0 part /mnt/root
Then open the file /mnt/root/etc/dhcpcd.conf:
sudo nano /mnt/root/etc/dhcpcd.conf
Uncomment the fallback lines at the end of the file:
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1
# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
Like this:
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
profile static_eth0
static ip_address=192.168.1.23/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
# fallback to static profile on eth0
interface eth0
fallback static_eth0
Starting the RaspberryPi
You can now unmount all mounted partitions (replace X with the letter of your device):
sudo umount /dev/sdX1
sudo umount /dev/sdX2
Disconnect the SD card and put it in the RasberryPi.
Connect the RaspberryPi to the network.
If you connect the RaspberryPi directly to your computer
You need to set up a static ip address to be able to connect to the raspberry pi since there is no DHCP server between the raspberry pi and your computer (no program to automatically assign ip addresses).
Go to your network manager and set up configuration for the wired network connection:
IP: 192.168.1.42
Netmask: 255.255.255.0
Gateway: 192.168.1.1
Connect to ssh
We consider that the IP address of the raspberry pi is 192.168.1.23
This is the address if you closely followed the tutorial. It is possible that the address is different if you chose another address.
To connect to ssh on the RaspberryPi you can use any tool you like, or the ssh command:
ssh pi@192.168.1.23
The default credentials are:
username: pi
password: raspberry
If you get an error like this:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:JYbNliQcRhEyxBn2Kj6OZR0Uq2qI5nUJIqhGgP+idwY.
Please contact your system administrator.
Add correct host key in /home/silvanosky/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/silvanosky/.ssh/known_hosts:16
ECDSA host key for 192.168.1.23 has changed and you have requested strict checking.
Host key verification failed.
You just need to remove the line starting with the IP address in the following file: ~/.ssh/known_hosts
You are now finished installing raspbian on your raspberry pi. You can continue the install here.