SETUID(1)

πŸ’– SETUID β€” bestie edition πŸ’–

okay so this is the setuid page from the General Commands Manual β€” the local one, iykyk πŸ’…


✨ NAME ✨

setuid β€” run a command with a different uid πŸ¦‹


🌸 SYNOPSIS 🌸

setuid username|uid   command [ args ]

πŸ’œ DESCRIPTION πŸ’œ

So setuid changes the user id, and then it runs the command you told it to run. That's the whole vibe ✨

And like β€” unlike some versions of su(1), this program never asks you for a password when it's executed with effective uid=root. no cap, no prompt, nothing πŸ™ˆ

Another thing: it does not touch the environment. It only changes the uid, and then it uses execvp() to find the command in the path and execute it. periodt.

πŸŽ€ little side note bestie: if the command is a script, then execvp() passes the command name to /bin/sh for processing. that's just how it goes πŸ’«

For example, this:

setuid  some_user  $SHELL

can be used to start a shell running as another user. slay πŸ‘‘

setuid is genuinely so useful inside scripts that are being run by a setuid-root user β€” like a script invoked with super β€” so that the script can execute some commands using the uid of the original user, instead of root. the way that works is lowkey iconic 🌈

That means unsafe commands (editors, pagers, the whole chaotic crew 😭) can be used in a non-root mode inside a super script. for example, an operator with permission to modify a certain protected_file could use a super command that simply does:

cp protected_file temp_file
setuid $ORIG_USER ${EDITOR:-/bin/vi} temp_file
cp temp_file protected_file
πŸ’€ WAIT. don't use this example directly. fr fr. If the temp_file can somehow be replaced by another user β€” as might be the case if it's kept in a temporary directory β€” then there will be a race condition in the time between editing the temporary file and copying it back to the protected file. that's a whole jumpscare, pls be careful 🫢

⭐ AUTHOR ⭐

Will Deich πŸ’–


and that's a wrap bestie πŸŽ€ this page lives in the local section, it's SETUID(1) β€” go forth and change those uids responsibly, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from