O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting the setuid and setgid bits with chmod

You have perhaps, by now, thought okay, but how exactly do I set these special permission bits?

This is simple: you use the chmod(1) command (or system call); this table shows how chmod can be used to set the setuid/setgid permission bits:

chmod via: Notation for setuid Notation for setgid
symbolic notation u+s g+s
octal notation 4<octal #> (eg. 4755) 2<octal #> (eg. 2755)

 

As a trivial example, take a simple Hello, world C program and compile it:

gcc hello.c -o hello

Now we set the setuid bit, then remove it, and set the setgid bit instead (in one operation: via the u-s,g+s parameter to chmod), then remove the setgid bit, all the while long-listing the binary executable so that the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required