Skip to content

Instantly share code, notes, and snippets.

@ilium007
Forked from kennwhite/alpine_password.sh
Created November 17, 2024 04:55
Show Gist options
  • Save ilium007/3a65fa6f7c48378cfb4dec1a1a2832e3 to your computer and use it in GitHub Desktop.
Save ilium007/3a65fa6f7c48378cfb4dec1a1a2832e3 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