Add a sudoer non-interactively from command line
I had a similar issue trying to get my docker container to allow jenkins scripts to use sudo commands without prompting for a password.
This was solved via the Dockerfile:
RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
To be able to do that, you should make sure you have the following line in your sudoers
file:
%sudo ALL=(ALL:ALL) ALL
You can customize the above line to change the permissions just as though %sudo
was a user.
That line will allow any users in the sudo
group to use sudo
.
Now to allow <username>
to use sudo
, you can just do usermod -a -G sudo <username>
as root, which adds <username>
to the sudo
group.
You could use cat
to append text to the end of /etc/sudoers
. First, make a backup copy of your /etc/sudoers
file. Then:
cat >> /etc/sudoers
...type one or more lines here...
[control-D]
Make absolutely sure to use two greater-than characters (>>
) and not just one, or else you will overwrite the entire contents of your file.