Sudo – how it works

The sudo(8) utility lets you run a program as another user; without further qualification, that other user is root. Of course, for security, you must correctly enter the root password (or as several distributions allow for desktop computing, the user's own password, if he belongs to a group called sudo).

This brings up a very interesting point: how exactly does the can-do-anything sudo(8) program work? It's simpler than you think! Refer to the following code:

$ which sudo/usr/bin/sudo$ ls -l $(which sudo)-rwsr-xr-x 1 root root 145040 Jun 13  2017 /usr/bin/sudo$ 

We note that the binary executable sudo is really a setuid-root program! So think about it: whenever you run a program with sudo, the sudo process runs with a root ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.