Tidak suka iklan? Pergi Bebas Iklan Hari ini

chmod Calculator Unix File Permissions Without Memorizing Octal

Diterbitkan pada
chmod Calculator: Unix File Permissions Without Memorizing Octal 1
IKLAN · HAPUS?

Unix file permissions trip up almost everyone at some point. The cryptic rwxr-xr-x di dalam ls -la output, the three-digit octal numbers, the difference between chmod, chowndan chgrp — it’s a lot to hold in your head. This is a reference you can bookmark instead.

If you need to compute a value right now, use the chmod Calculator — pick your permissions visually and it generates the correct octal or symbolic notation.

The Permission Model

Every file and directory has three permission sets:

  • Owner (u) — the user who owns the file
  • Group (g) — members of the file’s assigned group
  • Others (o) — everyone else

Each set gets three bits: read (r = 4), write (w = 2), execute (x = 1). Add them together to get the octal digit for that set. So rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, r-- = 4+0+0 = 4.

A three-digit octal like 755 means: owner gets 7 (rwx), group gets 5 (r-x), others get 5 (r-x).

Reading ls -la Output

-rwxr-xr-x 1 thien www-data 4096 Apr 10 10:00 deploy.sh
drwxr-x--- 2 thien www-data 4096 Apr 10 09:00 private/

The first character is the file type: - for a regular file, d for a directory, l for a symlink. The next nine characters are the three permission sets in order — owner, group, others — three characters each.

Common chmod Values

NilaiPemilikKelompokYang lainTypical Use
644rw-r–r–Web files (HTML, CSS, PHP)
755rwxr-xr-xDirectories, shell scripts
600rw-SSH keys, private config files
640rw-r–Config files (group-readable)
664rw-rw-r–Shared project files
700rwxPrivate scripts
777rwxrwxrwxDon’t use — gives everyone full control

Why 777 is wrong

chmod 777 is a common fix-it-later shortcut that tends to stay forever. It gives every user on the system — and in web contexts, any PHP process — write access to your files. On a shared server this is a security hole. On a VPS it’s sloppy. Fix the actual ownership problem with chown alih-alih.

chmod vs chown vs chgrp

PerintahWhat it changes
chmodRead/write/execute permissions on the file
chownWhich user (and optionally group) owns the file
chgrpWhich group owns the file
chmod 644 index.php           # Set permissions
chown www-data:www-data .    # Change owner and group
chgrp developers config.yml  # Change group only

Sticky Bit, setUID, setGID

These are represented by a fourth octal digit (as a prefix) or by letter substitutions in the symbolic notation.

  • Sticky bit (1 / t) — on directories, only the file owner can delete their own files. Used on /tmp.
  • setUID (4 / s on owner x) — the file runs as its owner, not the executing user. Used by sudo dan passwd.
  • setGID (2 / s on group x) — on files: runs with the file’s group. On directories: new files inherit the directory’s group, which is useful for shared project directories.
chmod +t /shared/dir          # Add sticky bit
chmod 1755 /shared/dir        # Sticky bit + standard 755
chmod g+s /var/www/project/   # setGID on a directory

In ls -l output, setGID on a directory looks like drwxrwsr-x; sticky bit looks like drwxrwxrwt.

Recursive Permissions: Be Careful with -R

chmod -R applies permissions to a directory and everything inside it. The common mistake: using 755 recursively sets execute on all files too, even when they don’t need it. A safer approach separates directories from files:

# Apply 755 to directories, 644 to files
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

Fixing Common Permission Problems

# Web server can't read your files (403 Forbidden)
chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

# SSH key refused (WARNING: UNPROTECTED PRIVATE KEY FILE)
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 700 ~/.ssh

# Script won't execute (Permission denied)
chmod +x deploy.sh

# PHP can't write to uploads directory
chown www-data:www-data wp-content/uploads
chmod 755 wp-content/uploads

Skip the Mental Math

Translating rwxr-x--- ke 750 in your head is doable, but tedious. The chmod Calculator at IO Tools lets you toggle permissions visually and instantly shows both the octal value and the symbolic notation — useful when you need to be certain before running chmod -R on a production directory.

Ingin bebas iklan? Bebas Iklan Hari Ini

Instal Ekstensi Kami

Tambahkan alat IO ke browser favorit Anda untuk akses instan dan pencarian lebih cepat

Ke Ekstensi Chrome Ke Ekstensi Tepi Ke Ekstensi Firefox Ke Ekstensi Opera

Papan Skor Telah Tiba!

Papan Skor adalah cara yang menyenangkan untuk melacak permainan Anda, semua data disimpan di browser Anda. Lebih banyak fitur akan segera hadir!

IKLAN · HAPUS?
IKLAN · HAPUS?
IKLAN · HAPUS?

Pojok Berita dengan Sorotan Teknologi

Terlibat

Bantu kami untuk terus menyediakan alat gratis yang berharga

Belikan aku kopi
IKLAN · HAPUS?