setgid example – wall

As a great example of setgid binaries, take a look at the wall(1) utility, reproduced from the script's output for convenience:

-rwxr-sr-x 1 root tty        30792 Aug 14  2017 wall

The wall(1) program is used to broadcast any message to all users console (tty) devices (typically the sysad will do this). Now, to write to a tty device (recall, folks, Chapter 1, Linux System Architecture, and the if it's not a process, it's a file Unix philosophy), what permissions do we require? Let's take the second terminal tty2 device as an example:

$ ls -l /dev/tty2crw--w---- 1 root tty 4, 2 Feb 19 18:04 /dev/tty2$ 

We can see that to write to the preceding device we either require root or we must be a member of the tty group. Peek again at ...

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.