Preserve shared's ordinary permissions and add SGID for group inheritance.
Which command is appropriate?
chmod g+s DIR adds SGID to a directory so new entries inherit its owning group.
Detailed explanation
chmod u+s sharedIncorrect. u+s sets SUID.
chmod g+x sharedIncorrect. g+x adds ordinary group execute/search permission only.
chmod o+t sharedIncorrect. o+t sets sticky bit.
chmod g+s sharedCorrect. chmod g+s shared adds the directory SGID bit.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); chmod 775 "$tmp"; chmod g+s "$tmp"; stat -c '%A %a' "$tmp"; chmod 700 "$tmp"; rmdir "$tmp"Expected result
drwxrwsr-x 2775Key points
- g+s
- The group execute position becomes s
- Directory group inheritance
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
g+s sets group inheritance; group write and execute permissions determine whether collaboration is usable.
Check the side effect
Check both the special bit and the directory's group ownership before creating shared content.