Sudo access issue

Hi,

I have given access to user mwadmin in shudders file as :

mwadmin  ALL:NOPASSWD:/www/* /usr/* /opt/*

However, not able to execute below command:

sudo mkdir -p /usr/test
[sudo] password for mwadmin:
Sorry, user mwadmin is not allowed to execute '/bin/mkdir -p /usr/test' as root. 

Please help.

You should carefully study the sudoers manual. There are multiple fundamental errors in that entry.

Regards,
Alister

OK, let me simplify the requirement,
We need a user to have all permissions under /usr Dir which is owned by root.
Please help.

So are you happy for your user to issue sudo /usr/bin/passwd root ?

There is the option there for someone to create something in any of those directories and then execute it as root, so if they can copy /sbin/shutdown to /www/private/application/area/my_shutdown and execute it there..... or the same with rm

Of course there is nothing really to stop them creating a script that simply calls a shell or su. Calling that with sudo would effectively log them on.

Blanket access is just asking for trouble. It may seem like a lot of effort, but your are best to find out what is actually needed. Why do you want to just give open access anyway?

Besides, if you need to allow execute of mkdir, it's best to have a rule that allows it rather than something wildly dangerous that doesn't actually do what you want.

Robin

Even if you set that up correctly, on your system, according to the diagnostic message, mkdir isn't under the /usr hierarchy.

More importantly, as I said, there are multiple errors in your attempt at a sudoers entry.

Did you edit sudoers using visudo? I suspect not, because it would have detected a syntax error (it should be an equals sign after the host specification, not a colon).

Aside from that, there are other non-syntactic, logical errors. Command specifications are comma-delimited. Your command specification will be treated as one long spec, not three. Only files in /www/ will match and the other two patterns are used to restrict the command's arguments.

Even if you delimited the command specifications correctly, the wildcards would not behave as you expect. As with shell pattern matching (aka globbing), the * will not match /. This means that /usr/* only matches files in /usr. It will match /usr/bin/, the directory itself, but not any of the executables of interest in /usr/bin and /usr/sbin.

Wildcards are unnecessary to match all files in a directory. The command specification can list a directory directly and that will be interpreted as matching any executable within it.

You really should spend an evening with the sudo, sudoers, and visudo documentation and inform yourself.

Regards,
Alister

1 Like