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
  • Select an option

  • Save ilium007/3a65fa6f7c48378cfb4dec1a1a2832e3 to your computer and use it in GitHub Desktop.

Select an option

Save ilium007/3a65fa6f7c48378cfb4dec1a1a2832e3 to your computer and use it in GitHub Desktop.

Revisions

  1. @kennwhite kennwhite revised this gist Apr 6, 2022. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions alpine_password.sh
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,12 @@
    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

    PW=$(head -c 32 /dev/urandom | base64) && echo -e "$PW\n$PW" | passwd appuser && echo $PW && 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
  2. @kennwhite kennwhite revised this gist Apr 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion alpine_password.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    adduser -D -g appuser appuser

    # Set random password at the 256 bit security level
    # 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 && echo $PW && unset PW

  3. @kennwhite kennwhite created this gist Apr 6, 2022.
    16 changes: 16 additions & 0 deletions alpine_password.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #! /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 random password at the 256 bit security level

    PW=$(head -c 32 /dev/urandom | base64) && echo -e "$PW\n$PW" | passwd appuser && echo $PW && 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:::