chmod and chown File permissions
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
ls -l <file>
chmod +x <file>
chmod 644 <file>
chmod 755 <dir>
chmod u+w,go-w <file>
chmod -R <mode> <dir>
chown <user>:<group> <file>
chown -R <user> <dir>
Concepts
| Digit | Bits | Meaning |
|---|---|---|
7 |
rwx | read, write, execute |
6 |
rw- | read, write |
5 |
r-x | read, execute |
4 |
r-- | read only |
0 |
--- | nothing |
Octal modes
chmod 644 <file>
chmod 755 <file>
chmod 600 <file>
chmod 700 <dir>
chmod 664 <file>
chmod 775 <dir>
chmod 00755 <dir>
Symbolic modes
chmod +x <file>
chmod a+x <file>
chmod u+x <file>
chmod g+w <file>
chmod o-rwx <file>
chmod u=rw,go=r <file>
chmod g=u <file>
chmod u+x,g-w <file>
chmod a-x <file>
Recursive changes
chmod -R <mode> <dir>
chmod -R a+rX <dir>
chmod -R u=rwX,go=rX <dir>
find <dir> -type d -exec chmod 755 {} +
find <dir> -type f -exec chmod 644 {} +
chmod -R -P <mode> <dir>
chmod -L -R <mode> <dir>
chmod --preserve-root -R <mode> /
Special bits
chmod u+s <file>
chmod g+s <dir>
chmod +t <dir>
chmod 4755 <file>
chmod 2775 <dir>
chmod 1777 <dir>
chmod u-s,g-s <file>
| Shown | Meaning |
|---|---|
s in owner x slot |
setuid with execute |
S |
setuid without execute |
s in group x slot |
setgid with execute |
S in group x slot |
setgid without execute |
t |
sticky with other-execute |
T |
sticky without other-execute |
Reading and copying modes
ls -l <path>
ls -ld <dir>
stat -c '%a %U:%G %n' <file>
chmod --reference=<ref> <file>
chmod -c <mode> <file>
chmod -v <mode> <file>
chmod -f <mode> <file>
chown
chown <user> <file>
chown <user>:<group> <file>
chown :<group> <file>
chown <user>: <file>
chown -R <user>:<group> <dir>
chown --reference=<ref> <file>
chown --from=<user> <new> <file>
chown -h <user> <link>
chown -R -H <user> <dir>
chgrp <group> <file>
sudo chown -R $USER: <dir>
umask
umaskumask -Sumask 022umask 077umask u=rwx,g=rx,o=
Recipes
find /srv/www -type d -exec chmod 755 {} +find /srv/www -type f -exec chmod 644 {} +chown -R www-data:www-data /srv/www
sudo chgrp -R team /srv/sharedsudo chmod -R g+rwX /srv/sharedsudo chmod g+s /srv/shared# new files now inherit group team
chmod 700 ~/.sshchmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keyschmod 644 ~/.ssh/id_ed25519.pub
ls -l <dir> | headsudo chown -R "$(id -un):$(id -gn)" <dir>



