Download Raspberry Pi OS Lite at https://www.raspberrypi.org/software/operating-systems/ and write it to SD card
wget https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-12-04/2020-12-02-raspios-buster-armhf-lite.zip
unzip 2020-12-02-raspios-buster-armhf-lite.zip
sudo dd bs=4M if=2020-12-02-raspios-buster-armhf-lite.img of=/dev/sdX status=progress conv=fsync
If you have no monitor available; enable ssh directly from here "SSH can be
enabled by placing a file named ssh
, without any extension, onto the boot
partition of the SD card". More info at
https://www.raspberrypi.org/documentation/remote-access/ssh/
Also, enable wifi by creating a wpa_supplicant.conf
and placing it in the
same spot as the ssh file above. See below for contents. More info at
https://www.raspberrypi.org/documentation/configuration/wireless/headless.md
While at it, you might want to change the /etc/hostname to something else than "raspberrypi" in the rootfs mount.
Login with pi/raspberry
and enable root password
sudo passwd root
If you're already on SSH, you need to enable root access over SSH now.
Add PermitRootLogin yes
to /etc/ssh/sshd_config
. Do not forget to
remove it when done.
then logout from pi
user:
logout
Now, login as root
with its new password rename user "pi" to "newname" and
change home dir name:
usermod -l newname -m -d /home/newname pi
groupmod -n newname pi
Then logout from root
logout
Change the password(!)
passwd
Confirm that the newuser still has sudo rights
sudo echo "Great success!"
Lock root account again:
sudo passwd -l root
If you enabled root access over SSH, this is the time to remove it from
/etc/ssh/sshd_config
.
If you enabled ssh and wifi with the boot partition thing before booting, then skip this section.
sudo systemctl enable ssh
sudo systemctl start ssh
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Contents of /etc/wpa_supplicant/wpa_supplicant.conf
:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=SE # https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
network={
ssid="SSID"
psk="PASSWORD"
}
To enable SSH access to the devices you will pull files from, you will need a SSH keypair.
ssh-keygen -t id25519
Append the public key ~/.ssh/id_ed25519.pub
to .ssh/authorized_keys
on the
devices you want to backup from.
Plug in an USB HDD and create a mount point, eg.:
sudo mkdir /mnt/extdisk
Get the UUID of the disk:
ls -l /dev/disk/by-uuid
Automount the disk
sudo nano /etc/fstab
Append something like to the end of /etc/fstab
:
UUID=251ee046-ee3d-4008-b41b-58f5c3726a32 /mnt/extdisk ext4 noexec,rw,user,errors=remount-ro 0 2
Mount the disk with
sudo mount -a
Download backup.sh
and make it executable
wget https://gist.github.com/simontegelid/5fbaa8478327b4f12ec26bed74ae314a/raw/ec916a42d6649c834fd1273635896bf24d9265e5/backup.sh
chmod +x backup.sh
Modify(!!!) backup.sh
and run it manually to verify that it does what you
want. There are as many backup scripts as there are people on earth, so you'll
want to modify yours too.
When you are satisfied, schedule it with cron
crontab -e
To run at midnight every day, append this line:
0 0 * * * /path/to/backup.sh
Download setup-hd-idle.sh
and make it executable
wget https://gist.github.com/simontegelid/5fbaa8478327b4f12ec26bed74ae314a/raw/ec916a42d6649c834fd1273635896bf24d9265e5/setup-hd-idle.sh
chmod +x setup-hd-idle.sh
./setup-hd-idle.sh