I love playing around with a Raspberry Pi*. Every time I decide to try a new project, I have to redo the basic setup to create a working system (install Rasbian and updates, setup language / keyboard stuff, expand disk space, import SSH keys, setup internet connection, ...). I know that I could do it one time, store a backup from the (micro)SD-card in a single .iso file and restore it every time I launch a new project. However, this also leads to missed updates, changes in versions etc. Therefore, I prefer starting from scratch every time.
I know, there are tons of tutorials and guides out there for basic Raspberry Pi setup, so I will not reinvent the world. This article can be seen as a quick go-through guide to remember the important steps. So if it is your first time setting up a Raspberry Pi, you better look for a beginner tutorial.
Steps
- Download and install Raspbian on a (micro)SD-card
- Enable SSH directly
- Apply basic configs (locate, expand disk, network)
- Update your system
- Add and enable a static IP address
- Add SSH keys
Guide
Preparation:
First, download Raspbian and put it on your (micro)SD card.
- Download latest Raspbian on https://www.raspberrypi.org/downloads/raspbian/
- If you decide to use the Imager Tool, install it, put your (micro)SD-card in and write the system on the card
- If you prefer the manual way, go on.
- Extract
.zipfile - Write the
.imgfile on the (micro)SD-card (not the file directly but with an image writer from your system)
If you don't want to connect a monitor, enable SSH directly:
Add empty ssh file into the boot partition
Add (micro)SD-card into your Raspberry Pi, but a LAN cable in and boot the system by using the power supply
Main config
After your Pi is up, use a monitor and keyboard if you want to work directly on a system or connect to it from another PC via SSH with ssh pi@192.168.X.X on Linux or Mac. Windows users can use Putty.
To find out the IP of your Pi, just look into your router web interface or try guessing it 😁
The default root username is pi with password raspberry.
Let's start with the main config:
Run sudo raspi-config (Navigation Hint: Select with space, navigate with arrows, enter-key for confirmation, tab-key for "jumping")
Select the first entry to change the password of the pi user
Select 2 Network Options
- Select N1 Hostname and change the name to something you prefer
Select 4 Localisation Options
Select I1 Change Locale and choose your location. I prefer to use the UTF-8 ones.
Select I2 Change Timezone and select your time zone
Select I3 Change Keyboard Layout (automatic process)
Perhaps select and change I4 Change Wi-fi Country
Select 7 Advanced Options
- Select A1 Expand Filesystem to be sure that all of the SD card storage is available for the OS
In the end, select 8 Update to update the tool (just to be sure)
For security and stability reasons it is important to keep your system up-to-date! So let's start by typing sudo apt-get update and sudo apt-get upgrade afterward to update and upgrade all your packages. Perhaps you need to accept the installation process by typing Y + Enter.
Static IP Address
I prefer giving my small microcontroller a static IP address and there are several ways to do it. The old, traditional way is to change the /etc/network/interfaces file. But Raspbian Jessi comes with a DHCP client daemon called DHCPCD. The suggested way is to change the config file of this daemon:
Make sure that the dhcpcd client is running. Check it with sudo service dhcpcd status. If it is not running, use sudo service dhcpcd start and sudo systemctl enable dhcpcd to start and enable it.
Now edit the config of the daemon with sudo nano /etc/dhcpcd.conf (or use another editor like vi or vim)
Use your arrow keys to get to the end of the file. There you can find an example static IP configuration (commented out). Add the following lines at the end of the file. Remember to change it to your local network configuration:
interface eth0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
Hint: The /24 stands for the subnetmask 255.255.255.0
Save the file with Cmd + O and hitting enter and close it with Cmd + X (when using nano)
It should work after restarting your system with sudo reboot
Import SSH keys
If you want to disable username and password login and use public / private key authentication instead, go on by
Copying your public SSH key from your client to your Raspberry Pi with ssh-copy-id -i ~/.ssh/id_rsa.pub pi@192.168.X.X
- Remember to change
~/.ssh/id_rsa.pubto your public SSH key location and192.168.X.Xwith your Raspberry Pi IP address - If you don't have SSH keys on your client, generate some with
ssh-keygen
If you want to disable username and password login:
Edit the config file with sudo nano /etc/ssh/sshd_config (or use another editor like vi or vim)
Search for the following keywords and set it to yes / no:
#[...]
PasswordAuthentication no
#[...]
ChallengeResponseAuthentication no
#[...]
PubkeyAuthentication yes
#[...]
RSAAuthentication yes
Save and close the file with Cmd + O, Enter and Cmd + X (when using nano)
Restart your SSHD service with sudo systemctl restart sshd
That's it! We are done! https://kingmaker3-de.com/
Footnote
- Raspbian changes its name to Raspberry Pi OS
- Raspberry Pi is a trademark of the Raspberry Pi Foundation. Logo by raspberrypi.com.