I want to change passwd of root of nspawn container, as I am creating container via ansible just after I created rootfs, as at very first it doesn't have any root password.

is it a good idea to change passwd by using replace module to replace root line in /etc/shadow file ?

is there any other way too to update the password non-interactively ?

I have tried :

echo user:pass | /usr/sbin/chpasswd

but echo is not working, a I am getting execv() failed: No such file or directory

1 Answer 1


passwd works for this case. It has an option --stdin. Do not use echo my-secret-password | passwd --stdin, because echo my-secret-password may become visible if someone runs ps, or maybe even in a log file if you are unlucky.



passwd root --stdin <<EOF
  • Thanks for the answer, but this is working fine in host, even the echo one which I mentioned above is running fine too in host, but failing in nspawn container
    – dgfjxcv
    Jul 12, 2018 at 9:52
  • my shadow file was messed up somehow, pwconv helped and its working now
    – dgfjxcv
    Jul 12, 2018 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .