Add set-user-ID to tool while preserving its existing ordinary permissions.
Which command is appropriate?
Symbolic u+s adds SUID. g+s is SGID, o+t is sticky, and + preserves existing ordinary permissions.
Detailed explanation
chmod g+s toolIncorrect. g+s sets set-group-ID.
chmod o+t toolIncorrect. o+t sets the sticky bit.
chmod u+x toolIncorrect. u+x adds execute permission, not SUID.
chmod u+s toolCorrect. chmod u+s tool adds the set-user-ID bit.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); chmod 755 "$tmp"; chmod u+s "$tmp"; stat -c '%A %a' "$tmp"; rm -f "$tmp"Expected result
-rwsr-xr-x 4755Key points
- u+s is SUID
- g+s is SGID
- + adds
Notes
- Environment: GNU coreutils 9.x / 空の一時ファイルを表示のみ
- Use a disposable file or directory when checking chmod calculations.
- Exact permission display can vary slightly with filesystem and distribution defaults.
Foundation review
Place the operation
The subject letter identifies the special bit family; u+s and g+s have different security effects.
Check the side effect
Verify the resulting s or S display and ensure the file is an intended executable before enabling SUID.