Raspberry PI Initial Installation and Preparation
This tutorial covers the initial installation and preparation of a Raspberry PI.
MATERIALS LIST:
- Raspberry PI 3 or higher
- MicroSD memory of at least 16Gb (best quality you can get)
- Raspberry PI OS Lite image
First we will create the memory as usual, install it in our Raspberry and turn it on. We will configure the necessary parameters, such as network, enable ssh access, update all packages to ensure we have the latest version running.
LOCALE CONFIGURATION
We will configure the locales, for this we will use the dpkg-reconfigure locales command, selecting only en_US:UTF-8. When we return to the system prompt, edit the /etc/default/locale file, and leave only the following entries:LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
DISABLE IPv6 SERVICES
Many times we do not need to have IPv6 services active, so it is better to disable them. To do this we must edit the /etc/sysctl.conf file, adding the following entries:###################################################################
# Disable IPv6 services
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
Then reload the services with sysctl -p
PACKAGE CLEANUP
To keep the operating system running more smoothly and securely, we must keep the system up to date and remove unused packages. A good tool is called deborphan which we can install using apt -y install deborphan.
First we perform a complete system update: apt -y update ; apt -y upgrade
Then we can restart the device and proceed with the cleanup part.
Now we will use the output of deborphan to clean up installed packages that are not used: deborphan | xargs apt -y remove
Then we will clean up the phantom packages, which were removed and left some traces in the system. For this we will use a series of concatenated commands:dpkg --list |grep "^rc" | cut -d " " -f3 | xargs dpkg --purge
Finally, we will use apt to remove other packages that are not in use:apt autoremove
FIXING APT KEY ERRORS
In some cases we will have an error about expired keys when using APT. The solution is quite simple:
- First we must locate the expired key, using the command
apt-key list |grep -A4 "trusted.gpg$".
$ apt-key list | grep -A4 "trusted.gpg$" Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). /etc/apt/trusted.gpg -------------------- pub rsa2048 2012-06-17 [SC] CF8A 1AF5 02A2 AA2D 763B AE7E 82B1 2992 7FA3 303E uid [ unknown] Raspberry Pi Archive Signing Key
In this case we will use the last 8 characters 7FA3303E - Export the key to a temporary location using
apt-key export 7FA3303E | gpg --dearmor -o /tmp/raspi.gpg, which will generate the key in the specified file. - Use the command
file /tmp/raspi.gpg - Remove the old key with
apt-key del 7FA3303E - Finally reinstall the updated key:
mv /tmp/raspi.gpg /etc/apt/trusted.gpg.d/ - Update the packages again with
apt -y update && apt -y upgrade - IMPORTANT: Follow the order so as not to lose the original key.