Thursday 10 September 2020

TIL passwd on Ubuntu no longer supports the stdin option

 In the past, I've used the passwd command in scripts to set a default password for new Linux accounts, as per this example: -

groupadd wasadmins

useradd -g wasadmins -d /home/wasadmin wasadmin

echo "passw0rd" | passwd wasadmin --stdin

( remembering that this is for NON-PROD boxes ONLY )

However, things appear to have changed, as that didn't work on Ubuntu 18.0.4

lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 18.04.4 LTS

Release: 18.04

Codename: bionic

as the --stdin option is not supported, as per this: -

echo "passw0rd" | passwd wasadmin --stdin

passwd: unrecognized option '--stdin'
Usage: passwd [options] [LOGIN]

Options:
  -a, --all                     report password status on all accounts
  -d, --delete                  delete the password for the named account
  -e, --expire                  force expire the password for the named account
  -h, --help                    display this help message and exit
  -k, --keep-tokens             change password only if expired
  -i, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --lock                    lock the password of the named account
  -n, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -q, --quiet                   quiet mode
  -r, --repository REPOSITORY   change password in REPOSITORY repository
  -R, --root CHROOT_DIR         directory to chroot into
  -S, --status                  report password status on the named account
  -u, --unlock                  unlock the password of the named account
  -w, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS
  -x, --maxdays MAX_DAYS        set maximum number of days before password
                                change to MAX_DAYS

Thankfully the internet provided an alternate: -


specifically this: -

echo "wasadmin:passw0rd!" | chpasswd

which worked a treat.

I also had to add the -m switch to my useradd command to force it to create a home directory, so we now have this: -

groupadd wasadmins
useradd -g wasadmins -d /home/wasadmin -m wasadmin
echo "wasadmin:passw0rd!" | chpasswd

which does the job nicely!

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...