Linux – How to avoid “root is not allowed to run sudo”

linuxrootsudosudoersubuntu 16.04

I am trying to execute some third-party installer script (ansible tower setup.sh) which needs to be started as root or via sudo as some of the commands rely on root privileges. However some commands during the script execution try to sudo. Don't ask me why, I think the setup script is a joint effort with some inconsistencies…

So the script fails, and I can reproduce it. I face this weird error any time trying to issue sudo as root, e.g.

root@machine:/home/someuser: sudo echo 1
root is not allowed to run sudo on <FQDN here>.  This incident will be reported.

I have never seen such thing in my previous experience with Ubuntu (and to be fair nor on Google currently.)

As it is not an option to find all the places and transform the script to not call sudo, I have to find a way for the root user to be able to perform sudo. The Ubuntu 16.04 server I am working on is configured in an exotic way by the private cloud provider of the company, inside domain (IDK whether this matters).

My /etc/sudoers looks like this:

#
# This file MUST be edited with the 'visudo' command as root.
# more bla bla
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
+unixadmin,+unixadminext      ALL= NOPASSWD: ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

about sudo:

root@machine:/home/someuser# which sudo
/usr/bin/sudo
root@machine:/home/someuser# ll /usr/bin/sudo
-rwsr-xr-x 1 root root 140816 Jun  7  2017 /usr/bin/sudo*    

What am I missing?

I added the root user to the sudo group but it did not solve the issue.

Best Answer

As root, run groups - Root isn't in the sudo group, because why would it ever need to be?

As to how to fix it, you could either add root to the sudo group, or you could put a check in any script that runs sudo (which you've discounted as a possibility for your particular problem, but it maybe a solution for others.

To add root to the sudo group:

(as root) usermod -a -G sudo root

Related Question