how to determine (though code .. or ACL) if a command would need needs root elevation i.e sun as sudo ? some commands need sudo .. some execute without sudo .. Is there a method to determine if sudo is needed ? any hints ?
Asked
Active
Viewed 77 times
1
-
https://unix.stackexchange.com/q/158488/386242 may be of use, even potentially duplicate. – RokeJulianLockhart Mar 12 '24 at 13:45
1 Answers
0
You can use stat
to examine the command's owner and execute permissions.
However most of the time the reason you need sudo
is not for how to invoke the command, but for the command's side effects: a couple of examples.
- use
crontab -e
to edit your crontab, butsudo crontab -e
to edit root's crontab chmod
to change permissions on your files,sudo chmod
to change permissions on any file

glenn jackman
- 85,964
-
Glenn - thanks but regrettably above doesn't work e.g getfacl /usr/bin/apt-get and getfacl /usr/bin/python3 both yield identical owner i.e root and identical permissions for owner , root and group .. where as apt needs sudo to run .. I am looking for a method where need for sudo can be determined through a code or CLI – Vinode Singh Ujlain Jul 12 '21 at 13:40
-
2That was exactly my point: you don't need root to run it, but you need root for the side effects. And you can't get that programmatically, you need to understand what the command does. – glenn jackman Jul 12 '21 at 14:20