I wanna create a user had random password for FTP in Docker. The section of Dockerfile like below:
RUN useradd web RUN export ftppass=`cat /proc/sys/kernel/random/uuid` RUN echo -e "$ftppassn$ftppass" | passwd web
But I got an error in last line:
New password: Retype new password: Sorry, passwords do not match. passwd: Authentication token manipulation error passwd: password unchanged
Why the passwords do not match even I using a same variable?
update:
I found the output of echo -e "$ftppassn$ftppass"
is:
Step 9/15 : RUN echo -e "$ftppassn$ftppass" ---> Running in ddd97df41d85 -e Removing intermediate container ddd97df41d85 ---> a64b606ea898 Step 10/15 : ...
Why it’s not works for echo -e
and where are my $ftppass?
Resolved, the new section of Dockerfile is:
RUN useradd web RUN cat /proc/sys/kernel/random/uuid > /etc/vsftp-password RUN echo "web:"`cat /etc/vsftp-password` | chpasswd RUN echo "ftp info web:"`cat /etc/vsftp-password`
Thanks anyone and happy new year~
Advertisement
Answer
Instead of using passwd
in a creative way, you should rather look at its manual page, which mentions chpasswd
in the See Also section.
The passwd
command is meant for interactive use, and it doesn’t read its input like most other programs, since the input is not echoed to the screen.