我正在尝试构建一个docker文件,其中一个reqt是创建一个具有sudo权限的用户。
这是bash脚本
# 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
和docker撰写文件。
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"]
当我运行此构建时,我收到以下错误。
chpasswd: (user testuser) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user testuser) password not changed
答案 0 :(得分:6)
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.