Cryptography
Change user password automatically
There are several way to change user password automatically.
Use usermod -p or useradd -p. It accepts a encrypted password. You can use the following commands to generate one:
# encpasswd=`openssl passwd -1 foo` # encpasswd=`perl -e 'print(crypt("foo","salt"),"\n")'` # usermod -p $encpasswd bar # useradd -p $encpasswd barUse passwd --stdin to set an user's password:
# echo "foo" | passwd --stdin bar
Change virtual machine password in a image file
Use this script chpasswd.sh:
#!/bin/bash # Stefan de Konink <dekonink@kinkrsoftware.nl> # Licensed under the GPL v3 or in your opinion any later version # # Usage: chpasswd.sh <imagefile> <passwd> DIR=/tmp/$(basename $1) mkdir $DIR mount -o loop $1 $DIR chroot $DIR /usr/sbin/chpasswd <<EOF root:$2 EOF umount $DIR rmdir $DIR
Do it:
# ./chpasswd.sh system.img new-root-passwd
