Configure setgid directories for shared work, create a controlled setuid helper, and lock down a world-writable drop zone using the sticky bit. Verify each special permission in real output so you can spot misconfigurations quickly in the field.
You’re preparing a multi-user development server. The dev team needs a shared workspace that preserves group ownership, a controlled helper that runs with root privileges, and a world-writable staging directory where users cannot delete each other’s files.
Special permission bits are powerful and dangerous. This lab is about setting them intentionally and proving state with verification output.
s in group perms.ls output.devs group exists.
sudo groupadd -f devs
-f makes the command idempotent. If the group
already exists, the command exits without failing, which is
useful in repeatable lab workflows.
/opt/devshare.
sudo mkdir -p /opt/devshare
This is the workspace target. We will assign group ownership and apply setgid so new files inherit the dev group.
devs.
sudo chgrp devs /opt/devshare
Group ownership is the foundation. setgid controls what group gets applied to files created inside the directory.
sudo chmod 2775 /opt/devshare
2 sets the setgid bit on the directory.
775 gives owner and group full access while
leaving read/execute for others. On shared dev servers, you
often pair this with a group umask so files land group-writable.
ls -ld /opt/devshare
drwxrwsr-x 2 root devs 4096 Jul 19 00:00 /opt/devshare
The group execute slot shows s when setgid is set
and group execute is enabled (that is the rws
in the middle).
setuid is a privilege escalation mechanism. In real systems,
you do not set this on random scripts or unknown binaries.
This lab uses /bin/true as a harmless stand-in.
sudo install -o root -g root -m 4755 /bin/true /usr/local/bin/helper
install copies the file and sets owner, group,
and mode in a single command. 4755 applies setuid
(4) plus executable permissions.
ls -l /usr/local/bin/helper
-rwsr-xr-x 1 root root 0 Jul 19 00:00 /usr/local/bin/helper
The owner execute slot shows s when setuid is set
and owner execute is enabled (the rws at the front).
sudo mkdir -p /tmp/shared && sudo chmod 1777 /tmp/shared
This is the classic pattern used by /tmp. The
directory is writable by everyone, but the sticky bit prevents
users from deleting files they do not own.
ls -ld /tmp/shared
drwxrwxrwt 2 root root 4096 Jul 19 00:00 /tmp/shared
The last execute slot shows t when sticky bit is
set and others execute is enabled (rwt at the end).
chmod 2775 <dir>
: Applies setgid on a directory so new files inherit the
directory’s group.
chmod 4755 <file>
: Applies setuid on an executable so it runs with the file
owner’s privileges.
chmod 1777 <dir>
: World-writable directory with sticky bit protection.
ls -ld <dir>
: Shows special bits in the permission string
(s / t).
s
(example: -rwsr-xr-x)
s
(example: drwxrwsr-x)
t
(example: drwxrwxrwt)