I'm building a jessie build of Debian. Passwords are saved in /etc/shadow
in the build tree, but they are salted obviously so I cannot change it just by editing the file. If this was my installed system, I could call passwd
, but here I want to change the password in the file in the build tree.
How do I change the root password before I flash a SD with a new build?
Best Answer
At the stage where you have a directory tree containing a file
…/etc/shadow
(before building the filesystem image), modify that file to inject the password hash(es) that you want to have.The easiest way to do that is with recent enough versions of the
chpasswd
tool from the Linux shadow utilities suite (Debian wheezy is recent enough) with the-R
option. Sample usage:with
passwords.txt
containing lines likeIf your build environment doesn't support
chpasswd -R
, you can use a tool that generates a password hash by calling thecrypt
function and inject that into theshadow
file by text manipulation. For example (untested code):