This episode applies security hardening to Alpine: regular updates with apk upgrade, strengthening SSH and the firewall, doas and default umask policy, and the lynis and fail2ban tools for auditing and brute-force detection.

Alpine is certainly designed to be secure from the start, but security doesn't stop at design — it's an ongoing process. Episode 13 assembles a hardening checklist you can apply to every Alpine server: regular updates, strengthening SSH and the firewall, doas and umask policy, and automated auditing with lynis.
The topics from episodes 9 and 10 will be woven together here into one coherent security policy. After this episode, you'll have a hardening procedure you can run repeatedly and turn into a production checklist.
Security patches are useless if they're not installed. Make updates a scheduled habit:
apk update
apk upgrade
apk info -uapk update refreshes the package index.apk upgrade updates all packages to the latest versions.apk info -u lists the packages that have updates available.For production servers, automate it with cron:
apk add cronie
crontab -eAn example cron line that runs updates every night:
0 2 * * * apk update && apk upgradeThe 0 2 * * * apk update && apk upgrade schedule runs updates at 02:00 every day. Pay attention to the update output — for production, test in staging before adopting full automation.
Combine the SSH hardening from episode 9 and the firewall from episode 10:
PermitRootLogin no
PasswordAuthentication no
MaxAuthTries 3
AllowUsers armanMake sure the firewall only opens the ports you need:
ss -tlnp
nft list rulesetThe ss -tlnp output lists all listening ports. Every port open without a need is an attack surface — close the ones you don't use by blocking them in the nft rules.
Apply the principle of minimal access:
A doas configuration stricter than the default:
permit nopass :wheel apk
permit persist :wheel
deny :guestThe permit nopass :wheel apk line lets the wheel group run apk without a password, while deny :guest blocks the guest user. Set the default umask in /etc/profile:
echo "umask 027" >> /etc/profile
umaskumask 027 results in files with stricter permissions — group read access only, with no permissions for others.
lynis is an open-source audit tool that scans the system and gives a hardening score:
apk add lynis
lynis audit systemThe lynis output shows the hardening score and a list of recommendations. Save the report for comparison over time:
lynis audit system --report-file /root/lynis-$(date +%F).txt
cat /var/log/lynis-report.dat | grep "hardening_index"grep "hardening_index" shows the numeric hardening index from the latest report.
fail2ban monitors logs and blocks IPs that make repeated login attempts:
apk add fail2ban
rc-service fail2ban start
rc-update add fail2ban defaultThe jail configuration for SSH lives in /etc/fail2ban/jail.local:
[sshd]
enabled = true
maxretry = 5
bantime = 3600
findtime = 600Check the jail status:
fail2ban-client status
fail2ban-client status sshdfail2ban-client status sshd shows the IPs currently blocked along with violation statistics.
Info
Hardening isn't a one-time event. Make lynis and apk upgrade a monthly routine, and track the hardening score over time so changes that weaken security are caught quickly.
Episode 13 wove Alpine's security hardening into one coherent policy: regular updates with apk upgrade, strengthening SSH and the firewall, doas and umask policy, auditing with lynis, and brute-force detection with fail2ban.
Key takeaways:
In the next episode, episode 14, we'll cover musl libc: implications and compatibility — the differences from glibc binaries, why some prebuilt applications don't run, and using gcompat as a compatibility layer.