Reputation: 20856
Im trying to build a docker file and one of the reqt is to create a user with sudo permissions.
Here is the bash script
# quietly add a user without password
adduser --quiet --disabled-password --shell /bin/bash --home /home/newuser --gecos "testuser" newuser
# set password
echo "testuser:testuser" | sudo chpasswd
and the docker compose file.
FROM ros
RUN apt-get update
RUN apt-get install -y sudo
ADD run.sh /usr/local/bin/run.sh
RUN chmod +x /usr/local/bin/run.sh
CMD ["/usr/local/bin/run.sh"]
When I run this build I get the following error.
chpasswd: (user testuser) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user testuser) password not changed
Upvotes: 7
Views: 15338
Reputation: 6079
I think you're misinterpreting the requirements. Creating an user with sudo permissions is different from creating an user with the sudo
command.
Depending on the distribution, an user may run sudo
if it belongs to the wheel or sudo group (the latter is the case with Ubuntu, which is the base image used by ros).
I strongly suggest that you use the useradd
command instead of adduser
. The latter is different in Debian & RedHat based distributions, unlike the former which is the same across Linux distributions and even *BSD if you don't use the long options. Also, the former lets you specify the supplementary groups in the command line (-G
option).
useradd -m -s /bin/bash -G sudo newuser
If you use the -p
option you could also supply the password in encrypted form (the term in the manpage should be hashed form) without the need to use chpasswd
later. Use the output of mkpasswd -m sha-512
. (The mkpasswd
command is present in the whois package). If you're going to use chpass
, use the -e
option to supply the password in encrypted form. Never use plaintext.
Upvotes: 9