Skip to content

Instantly share code, notes, and snippets.

@greew
Last active January 22, 2021 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greew/a80bd776e7fc9057ed22b5adbfca986f to your computer and use it in GitHub Desktop.
Save greew/a80bd776e7fc9057ed22b5adbfca986f to your computer and use it in GitHub Desktop.
Installing my Raspberry Pi

Installing Raspberry Pi with backup, DLNA and web server

This is mostly for my own reference - I tend to forget such setup settings after a few weeks, but if you can use any of it, feel free to copy along.

Currently, I'm using my Raspberry Pi for backup, DLNA streaming movies to my smart TV and for home web server, running a few internal services.

Required Hardware

Installing Raspbian

Download and install Raspberry Pi Imager onto a computer with an SD card reader (or use a card reader peripheral your computer (not the Pi, that is).

Insert the SD card into this other computer and install the Raspbian Lite distro on the SD card (I don't care about the Desktop environment, as I run it headless and only use SSH to log in to).

When the new distro has been installed, don't remove the SD card but go to the boot folder of the card. Add an empty file with the name ssh. This ensures that SSH is enabled on first boot. That way we can use it headlessly (see more)

When finished, unmount the SD card, pull it from your computer and insert the SD card in the Pi, put it in the case, connect external hard drive, ethernet and - at last - the power. The Pi will now start up.

Initial setup

To connect to the Pi, you need the IP address that your network has given it.

I'm using a few Deco M9 Plus as home network and can via the connecting app see IP addresses of all connected devices - also my Pi. You may probably find it by logging into your router (or whichever device runs our DHCP).

If possible - setup a static IP address, so you don't need to find the new IP address constantly.

Now, log in via SSH

ssh pi@<pi IP>

The default password (as of writing) is raspberry.

First point of order is to change the default password

passwd 

Fill in the old password and then your password twice, as requested.

Then logout.

Setup SSH and security

The SSH server has already been started, but it currently allows for password logins. We don't want this, but instead want public/private key-pairs.

I already have a key-pair, so I'll just copy this to the server. If you don't have a public/private key-pair, you will need to create it. Github itself has a nice guide.

You will have to copy the key from you own computer to the Pi. You can use the following command which takes care of copying the key and also placing it in the correct location on the Pi.

ssh-copy-id -i <path-to-your-private-key-file> pi@<pi IP>

You'll be asked to enter your Pi password. Use the new password.

Log in to the Pi again the same way as before ssh pi@<pi IP>. If you're asked for as password, something has gone wrong.

Now, we need to disable logins using passwords and root login.

Edit the file /var/ssh/sshd_config and replace the following settings:

From To
#PasswordAuthentcation yes PasswordAuthentcation no
#PermitRootLogin prohibit-password PermitRootLogin no

Then, restart the ssh server

sudo service sshd restart

Other initial setup

Install some other practical tools.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vim git curl wget zip tmux

Setup external hard drive

Make sure the hard drive is connected and powered on.

Check the different hard drives and their names:

sudo fdisk -l

Mine shows a lot a info, but what's important to me is this:

Disk /dev/sdb: 1.8 TiB, 2000398933504 bytes, 3907029167 sectors
Disk model: Expansion
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0xd28e4b57

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1        2048 3907026943 3907024896  1.8T 83 Linux

For the rest we need the disk name and disk identifier.

  • Disk name: /dev/sdb
  • Disk identifier: 0xd28e4b57

Format the disk in ext4.

sudo mkfs.ext4 <name>

Then add the hard drive to the mount table so that it will be mounted on boot.

Edit /etc/fstab

sudo vim /etc/fstab

Add the following line at the bottom of the file:

Setup DLNA

https://pimylifeup.com/raspberrypi-minidlna/

Setup web server (nginx + PHP 7.4)

Add apt repository and install nginx and PHP 7.4

sudo apt-get update
sudo apt-get -y install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt-get update
sudo apt-get install nginx php7.4-fpm

Inspiration from: https://raspberrypi.stackexchange.com/questions/108149/php-7-4-on-raspbian

Setup OpenVPN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment