1

I have a docker image that I use to test install scripts in a CI setup. The install scripts are meant to be run by non-root users so the commands in the scripts use sudo quite often.

I added the following which allows me to avoid password prompts while running sudo commands.

RUN adduser --disabled-password --gecos '' user
RUN adduser user sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER user

However, this doesn't work with sudo validate (sudo -v). No matter what I try, sudo -v will always ask for a password. I don't want to remove sudo -v from the install scripts.

Anyone know why this is? I tried on both ubuntu:16.04 and ubuntu:18.04 docker images.

0
1

If you have a newer version of sudo, you may also need to configure verifypw

Defaults verifypw = any

You can read the docs, but basically this means that if you match any NOPASSWD line it doesn't ask for a password. The default is all which means you have to match all the groups and the user with NOPASSWD to skip the password.

So if you're user is also in the root or wheel or sudo groups and they don't say NOPASSWD, then it'll ask.

1
  • Thanks a ton! that seems to have done it. I'm surprised I never came across this in my searches since it only applies to using sudo -v – Ian Colwell Feb 26 '20 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.