If you’re anything like me you hate installing software and operating systems. A lot of the process includes arbitrary steps you do very infrequently to be able to recall properly, or maybe arcane knowledge about a particular software or hardware system that you have to know or it won’t work. Beyond that it can be tedious and keeps you from the real work or project you’d like to get to. Even Linus Torvalds doesn’t like it.
This is a short guide I wrote a while ago on how to install and configure alpine linux on a raspberry pi zero w. It’s similar in purpose to my guide on void linux for the raspberry pi 3b+. It’s designed to walk you through some basic configuration if you’re new to linux or alpine. By the end you’ll be able to ssh to a basic user to do whatever you need.
-
Ingredients List
- Raspberry Pi Zero W
- Microsd Card
- (Optional) my setup script
-
Write the image to your sdcard and install unpack alpine to your pi
- Use my script if you want, but make sure to change
PIDRIVE
to your sdcard device (lsblk
to find your card device) andIMGVER
andIMGREV
to the latest values (as of this writing change IMGVER->‘3.12’ and IMGREV->‘0’ . - Otherwise you can download the armhf image and install manually
- Use my script if you want, but make sure to change
-
Insert the microsd card, hook the pi up, and turn it on
- Login as ‘root’ (password is empty)
- The default login shell is ash
-
Basic configuration
- Run the setup wizard
setup-alpine
- This wizard will set up the keyboard, hostname, internet connection, ntpd, and other stuff
- I had a problem with the busybox ntp daemon, so I left the default ntp daemon option (chrony)
- Add a few basic packages (rng, man, vim, bash, sudo)
apk update && apk upgrade
apk add rng-tools man vim bash sudo
- rng service configuration (this fixes dhpc issues that occur on reboot) this guide was helpful
service rngd start
rc-update add rngd boot
rc-update add wpa_supplicant boot
rc-update del networking boot
rc-update -u
- The wizard should enable the sshd service automatically (assuming you enabled network access), but by default the root user can’t be ssh to with a password.
- For ssh you can either edit ‘/etc/ssh/sshd_config’ (to enable root ssh) or add a new user.
- I elected for the latter approach because I try to minimize using root, even on embedded systems.
- Run the setup wizard
-
Create a standard user
- Alpine uses its own
adduser
andaddgroup
commands, which work a little differently from theuseradd
andgroupadd
that I’m more familiar with. - Create a standard user called with a
bash
login shell, membership towheel
andusers
groups, and a password:adduser -S <user> -h /home/<user> -s /bin/bash -G wheel
addgroup <user> users
lbu include /home/<user>
passwd <user>
- Add wheel to sudoers to give standard user sudo ability
visudo
- uncomment line (remove
#
):%wheel ALL=(ALL) ALL
- commit changes and reboot
lbu commit -d
reboot
- Alpine uses its own
-
Client SSH conveniences (Optional)
- Go to the terminal on your client (remote) machine
- Get your pi LAN ip address
- You could have got this during
setup-alpine
when dhcp was set up - If not you can get it with
sudo arp-scan -l
- You could have got this during
- Add the pi hostname to your client machine ‘/etc/hosts’ file
sudo vim /etc/hosts
<host_ip>
- Add your default key to be used as authentication (if you don’t have one, generate a keypair with
ssh-keygen
)ssh-copy-id <user>@<host>
- Test ssh connection
ssh <user>@<host>
-
Configure the standard user
- Connect to pi from client
ssh <user>@<host>
- Create an empty .profile file
touch .profile
- (Optional) Add whatever you want to your .profile
vim .profile
- Symlink .bash_profile and .zprofile to .profile
ln -s .profile .bash_profile
ln -s .profile .zprofile
- Connect to pi from client