- When you run an executable, sometimes the OS will deny your
permission to. For example running
make installwith the prefix being a system path will need
sudo, while with the prefix being a non-system path will not be asked for
sudo. How does the OS decide that running an executable would require more privilege than a user has, even before the program does something?
- Sometimes, running a program will not be denied permission, but the
program will be able to do more things if it is run with
sudo. For example, when running
duon some system directory, only with
sudoit will be able to access some directory. Why does the OS not deny permission of running such a program, or friendly notify more privilege is preferred, before the program can run?
- Is it true that whenever
suwill also work, and whenever
sudowill also work? or with
su, a user can do more than with
sudo? How does the OS decide when
sudoworks, and when
For the purposes you have described, the OS doesn't decide whether you need sudo to initially run the program. Instead, after the program starts running and then tries to do something that is not permitted by the current user (such as writing a file to
One of the striking features of
tl;dr Access is determined by the user who is running application, and
It doesn't know. UNIX manages permissions not on application level but on filesystem level: permissions are granted for users to access specific files. Applications then are run on behalf of user - each running process has user associated with it. That user is used to determine permissions for that application. Sudo works by running applications on behalf of other user (with permissions associated with that another user), namely
As for your examples:
Yes and no. Yes, if program is actually run, it should behave the same under both
Last note: how application handles denial of access (wherher it aborts or ignores or warns user) is up to application.