Skip to content

Instantly share code, notes, and snippets.

@kennwhite
Last active July 12, 2023 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennwhite/54af16fa003fa3ec69c471ef9bb26b1b to your computer and use it in GitHub Desktop.
Save kennwhite/54af16fa003fa3ec69c471ef9bb26b1b to your computer and use it in GitHub Desktop.
Non-interactive user create & password change for Alpine Linux
#! /usr/bin/env sh
# Create unprivileged Alpine linux user. Run this script as root/sudo
# Don't prompt for password and make group same as username, default path & shell
adduser -D -g appuser appuser
# Set a decent random password (aiming for a 256 bit security level, but better than "monkey")
PW=$(head -c 32 /dev/urandom | base64) && echo -e "$PW\n$PW" | passwd appuser && unset PW
# Alternatively, to echo: PW=$(head -c 32 /dev/urandom | base64) && echo -e "$PW\n$PW" | tee /dev/stderr | passwd appuser && unset PW
# Results in something like this
# /etc/password: appuser:x:1000:1000:appuser:/home/appuser:/bin/ash
# /etc/shadow: appuser:$6$M2LLoqMEfhFOc3Qe$W.FOl61we8PIte.KDMWxifg/TVdFgPKdIuMDISH74laCtA7t3OorjOiGPLdGPbTizczPUu17EaXoH32hu1OKo1:19088:0:99999:7:::
# To revert: deluser --remove-home appuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment