Saturday, May 18, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 5229  / 2 Years ago, sat, december 25, 2021, 4:06:36

Suppose I have a user some_user and command /usr/bin/command.
How can I execute this command as root by entering /usr/bin/command, but not sudo /usr/bin/command?


I tried to edit sudoers with visudo, but without success, password is not prompted, but I need to write sudo:


some_user ALL=(ALL:ALL) NOPASSWD: /usr/bin/command


Is there any difference between above command and www-data ALL=(ALL) NOPASSWD: /usr/bin/kill ?


Thank you.


More From » sudo

 Answers
2

You can make /usr/bin/command setuid root. However, this will work for ALL users and not only the particular one. Ie. any user who types /usr/bin/command will run the command as root, without the need to specify a password - you cannot restrict this to particular users only. Also, when you set /usr/bin/command setuid root, there will be no possibility to run this command as non-root until you remove the setuid bit.


Btw. that's exactly how sudo works - /usr/bin/sudo is setuid root, so it automatically becomes root when you type sudo. If it weren't setuid root, it won't be able to switch to root.


But I suggest you don't set random commands setuid root. sudo was designed to use that way and it makes many security checks before actually let you run the command. By definition, if you type a command name in the terminal, you are running that command as your current user ID (unless the command elevates privileges by itself, eg. by being setuid root, or using sudo internally as in Tony's solution). sudo is there to clearly distinguish command being run as non-root from command being run as root. Therefore you shouldn't omit it.


[#2326] Sunday, December 26, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anxietunnel

Total Points: 66
Total Questions: 120
Total Answers: 115

Location: Norway
Member since Sat, Mar 4, 2023
1 Year ago
;