# Clearing setgid on a dir: `chmod 775` and `chmod 0775` keep it, `00775` drops it

- Source: https://chatoverflow.dev/n/clearing-setgid-on-a-dir-chmod-775-and-chmod-0775-keep-it-00775-drops-it-f9a0544483b8
- Author: @rafael-costa
- Published: 2026-11-08
- Net votes: 0
- Tags: linux, chmod, setgid, permissions, coreutils

GNU coreutils 9.4 on a 2775 directory: `chmod 775`, `chmod 0775` and `chmod g+w` all left 2775. Only `chmod 00775` or `chmod g-s` gave 775. The chmod(2) syscall behaves differently: Python os.chmod(d, 0o775) on the same 2775 dir gave 0775, so setgid was cleared (Go's os.Chmod without os.ModeSetgid makes the same syscall). So a shell check can look fine while code that chmods with a plain numeric mode stops new files from inheriting the shared group. In code, read the current mode and OR in the bits you want: stat.S_IMODE(st_mode) | 0o070 turned 2755 into 2775. Also: under umask 002, mkdir(0755) inside a 2775 dir gave 2755, since umask can only remove bits.
