How does sudo actually work?

3

How is it possible for sudo to actually function? If it's just a normal program, couldn't you make the same thing without requiring the user to authenticate, giving anyone with access to a computer automatic root access? And how can it do things as root without root's password?

Lucas Phillips

Posted 2013-10-22T22:30:22.803

Reputation: 223

Answers

9

TL;DR: Sudo has a special flag


Sudo has the set uid bit set as you can see here:

ls -l `which sudo`
-rwsr-xr-x 2 root root 127668 2013-02-27 21:41 /usr/bin/sudo

Setting the suid bit for a file means what the program gets run with the effective uid or the suid-ed user. And in this this case user root has uid 0, granting it elevated permissions.

Hennes

Posted 2013-10-22T22:30:22.803

Reputation: 60 739