1. Latar Belakang
Pada hari ketiga pembelajaran Sistem Administrasi Linux di Perwira Learning Center, saya mempelajari penggunaan perintah chmod (change mode) untuk mengatur hak akses file dan direktori. Chmod adalah salah satu perintah paling penting dalam administrasi sistem Linux karena menentukan siapa yang boleh melakukan apa terhadap suatu file. Pemahaman mendalam tentang chmod diperlukan untuk menjaga keamanan sistem, mengelola akses multi-user, dan mencegah konflik permission yang dapat mengakibatkan kerentanan keamanan atau error sistem.
2. Alat dan Bahan
2.1 Perangkat Lunak
- Ubuntu Server 22.04 LTS
- Terminal Linux
- Text editor (nano)
- Man pages (
man chmod)
2.2 Perangkat Keras
- Laptop dengan VirtualBox
- Virtual Machine Ubuntu Server
- Storage yang cukup untuk praktik file management
3. Pembahasan
3.1 Fungsi Command chmod
chmod (change mode) adalah perintah Linux untuk mengubah permission (hak akses) dari file dan direktori. Perintah ini merupakan core utility dalam manajemen keamanan sistem Linux.
Sintaks dasar:
chmod [options] mode file/directory
Fungsi utama:
- Mengatur read, write, execute permission
- Mengontrol akses untuk user, group, others
- Menerapkan special permissions (SUID, SGID, sticky bit)
- Melakukan perubahan recursive pada direktori
3.2 Metode Symbolic (u,g,o,a + r,w,x)
Metode symbolic menggunakan kombinasi huruf untuk mengubah permission:
Komponen Metode Symbolic:
- Subjek (siapa yang diubah):
u= user/ownerg= groupo= othersa= all (u+g+o)- (kosong) = default ke
a
- Operasi (apa yang dilakukan):
+= tambah permission-= hapus permission== set permission persis
- Permission (apa permissionnya):
r= readw= writex= execute
Contoh Penggunaan Metode Symbolic:
# Menambah permission chmod u+x script.sh # Tambah execute untuk user chmod g+w document.txt # Tambah write untuk group chmod o-r config.cfg # Hapus read untuk others chmod a+rx program # Tambah read+execute untuk semua # Mengatur permission spesifik chmod u=rw,g=r,o= private.txt # User: rw, Group: r, Others: none chmod go= public.sh # Hapus semua permission untuk group dan others # Kombinasi multiple chmod u+x,g-w,o+r file.txt
3.3 Metode Numeric (755, 644, 777) dan Cara Menghitung
Metode numeric menggunakan angka octal (basis 8) untuk merepresentasikan permission:
Sistem Angka Octal:
Setiap digit mewakili satu entitas:
- Digit 1: User/Owner permission
- Digit 2: Group permission
- Digit 3: Others permission
Nilai Permission:
0 = --- (no permission) 1 = --x (execute only) 2 = -w- (write only) 3 = -wx (write + execute) 4 = r-- (read only) 5 = r-x (read + execute) 6 = rw- (read + write) 7 = rwx (read + write + execute)
Cara Menghitung Manual:
- Tentukan permission untuk setiap entitas:
- User: rwx = 4+2+1 = 7
- Group: r-x = 4+0+1 = 5
- Others: r-- = 4+0+0 = 4
- Gabungkan: 7(user) 5(group) 4(others) = 754
Contoh Permission Numeric Umum:
# Permission umum chmod 644 file.txt # rw-r--r-- (file biasa) chmod 755 script.sh # rwxr-xr-x (executable) chmod 600 secret.txt # rw------- (private) chmod 750 shared.sh # rwxr-x--- (executable, group bisa run) chmod 777 dangerous.sh # rwxrwxrwx (SEMUA BISA APA SAJA!) # Untuk direktori chmod 755 folder/ # drwxr-xr-x (web directory) chmod 700 private/ # drwx------ (hanya owner) chmod 775 team/ # drwxrwxr-x (shared dalam group)
Latihan Perhitungan:
# Soal: File dengan permission rw-rw-r-- # Penyelesaian: # User: rw- = 4+2+0 = 6 # Group: rw- = 4+2+0 = 6 # Others: r-- = 4+0+0 = 4 # Hasil: 664 # Verifikasi: chmod 664 file.txt ls -l file.txt # Output: -rw-rw-r--
3.4 Contoh Penggunaan chmod pada File dan Folder
Scenario 1: Setup Web Server Directory
# Membuat struktur web directory mkdir -p /var/www/mywebsite/{html,cgi-bin,logs,uploads} # Set permission untuk web content chmod 755 /var/www/mywebsite/ # Direktori utama chmod 755 /var/www/mywebsite/html/ # HTML files chmod 755 /var/www/mywebsite/cgi-bin/ # CGI scripts chmod 750 /var/www/mywebsite/logs/ # Log files (hanya owner & group) chmod 775 /var/www/mywebsite/uploads/ # Upload directory (writable) # Set permission file chmod 644 /var/www/mywebsite/html/*.html # File HTML chmod 755 /var/www/mywebsite/cgi-bin/*.cgi # CGI scripts (executable)
Scenario 2: Setup Home Directory User Baru
# Set permission home directory baru mkdir /home/budi chmod 700 /home/budi # Hanya budi yang bisa akses # File-file di dalam home touch /home/budi/{.bashrc,.profile,documents.txt} chmod 644 /home/budi/.bashrc # Readable oleh semua chmod 600 /home/budi/documents.txt # Private
Scenario 3: Shared Project Folder untuk Tim
# Membuat grup tim sudo groupadd tim_dev # Membuat folder shared mkdir /projects/shared sudo chown root:tim_dev /projects/shared chmod 2775 /projects/shared # SGID aktif (2), rwxrwxr-x # File baru otomatis punya group tim_dev touch /projects/shared/plan.txt ls -l /projects/shared/plan.txt # Output: -rw-rw-r-- 1 ibra tim_dev ...
3.5 Risiko Permission 777 dan Kapan Tidak Boleh Digunakan
Apa itu Permission 777?
chmod 777 file.txt # Hasil: -rwxrwxrwx # Arti: SEMUA USER bisa baca, tulis, dan eksekusi!
Risiko Permission 777:
- Security Hole Besar: bash
# Contoh berbahaya: chmod 777 /etc/passwd # Sekarang siapa pun bisa edit file user sistem!
- Malware dan Exploit:
- Hacker bisa inject malicious code
- Virus bisa menular dengan mudah
- Backdoor bisa dibuat oleh siapa saja
- Accidental Damage:bash
# User biasa bisa hapus file penting rm /important/system.conf # Bisa dilakukan jika file 777
- Privilege Escalation:
- Program dengan SUID + 777 sangat berbahaya
- Bisa digunakan untuk mendapatkan root access
Kapan 777 BOLEH Digunakan:
# ❌ SALAH (JANGAN LAKUKAN!): chmod 777 /etc/ chmod 777 /home/ chmod 777 /usr/bin/ # ✅ BENAR (kasus sangat terbatas): # 1. Directory /tmp (tapi Linux sudah pakai sticky bit) chmod 1777 /tmp # dengan sticky bit # 2. Testing environment sementara # (hapus segera setelah testing selesai) # 3. Beberapa log directory dengan kontrol ketat # (masih lebih baik pakai 775 dengan group tertentu)
Alternatif yang Lebih Aman:
# Daripada: chmod 777 /uploads/ # Lebih baik: chmod 775 /uploads/ # Group bisa write # ATAU chown www-data:www-data /uploads/ # Milik web server chmod 755 /uploads/ # Web server bisa manage
3.6 Best Practice Permission untuk Project & Server
Permission Standard untuk Berbagai Tipe:
# 1. File Konfigurasi chmod 644 config.yml # rw-r--r-- (owner edit, lainnya baca) # 2. Script Executable chmod 755 deploy.sh # rwxr-xr-x (owner full, lainnya run saja) # 3. File Log chmod 640 app.log # rw-r----- (owner edit, group baca) # 4. File Sensitif (password, key) chmod 600 .env # rw------- (hanya owner) # 5. Directory User Home chmod 700 /home/ibra/ # drwx------ (hanya owner) # 6. Shared Directory dalam Tim chmod 2770 /team/shared/ # drwxrws--- (SGID + group access) # 7. Web Root Directory chmod 755 /var/www/html/ # drwxr-xr-x (web server) # 8. CGI Scripts chmod 755 /cgi-bin/*.cgi # -rwxr-xr-x (executable) # 9. Socket Files chmod 755 /run/mysock # Harus executable untuk komunikasi # 10. Device Files chmod 666 /dev/ttyS0 # Serial port (rw-rw-rw-)
Security Checklist:
# Script untuk audit permission #!/bin/bash echo "=== PERMISSION AUDIT ===" # Cari file dengan permission 777 find /home -type f -perm 777 2>/dev/null echo "File dengan 777 ditemukan" # Cari directory world-writable find / -type d -perm -0002 ! -perm -1000 2>/dev/null | head -20 # Cari file SUID/SGID yang mencurigakan find / -type f -perm /6000 2>/dev/null | grep -v "^/proc\|^/sys"
3.7 Latihan Kasus Perubahan Permission
Kasus 1: Membuat Script Deploy yang Aman
# File asli: -rw-r--r-- (644) touch deploy.sh echo '#!/bin/bash' > deploy.sh echo 'echo "Deploying..."' >> deploy.sh # Salah: chmod 777 deploy.sh # Benar: chmod 755 deploy.sh # -rwxr-xr-x # Atau jika hanya untuk Anda: chmod 700 deploy.sh # -rwx------
Kasus 2: Shared Database Configuration
# File database config sensitif # Awal: -rw-r--r-- (644) <- TERLALU TERBUKA! # Solusi: chmod 640 db_config.cnf # -rw-r----- chown app:devteam db_config.cnf # Hanya user 'app' dan group 'devteam' yang bisa akses
Kasus 3: Fixing Upload Directory WordPress
# Problem: WordPress upload gagal # Lokasi: /var/www/html/wp-content/uploads/ # Analisis: ls -ld /var/www/html/wp-content/uploads/ # Output: drwxr-xr-x (755) <- web server tidak bisa upload # Solusi 1 (aman untuk shared hosting): chown www-data:www-data uploads/ chmod 755 uploads/ # Solusi 2 (jika perlu writable): chmod 775 uploads/ # TETAPI pastikan tidak ada file 777 di dalamnya!
Kasus 4: Multi-user Project Collaboration
# Membuat environment project mkdir -p /projects/webapp/{src,logs,temp,bin} chmod 755 /projects/webapp/ # src: hanya read untuk team chmod 750 /projects/webapp/src/ # logs: writable oleh aplikasi chmod 770 /projects/webapp/logs/ # temp: writable oleh semua process chmod 777 /projects/webapp/temp/ # HANYA temp, dengan monitoring # bin: executable scripts chmod 750 /projects/webapp/bin/
Kasus 5: Recovery dari Permission Error
# Accidentally: chmod -R 777 /etc/ (JANGAN COBA DI PRODUKSI!) # Recovery steps: # 1. Boot dari live CD/USB # 2. Mount filesystem # 3. Restore permission dari backup # Alternatif (jika ada package manager): sudo apt install --reinstall coreutils # atau untuk spesifik directory: sudo dpkg -S /etc/passwd | cut -d: -f1 | xargs sudo dpkg-reconfigure
3.8 Tips Tambahan untuk chmod
Using Reference Mode:
# Copy permission dari file lain chmod --reference=source.txt target.txt # Contoh praktis: chmod --reference=/etc/nginx/nginx.conf new_config.conf
Verbose Mode:
# Melihat perubahan yang dilakukan chmod -v 755 script.sh # Output: mode of 'script.sh' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x)
Recursive dengan Filter:
# Hanya ubah file .sh find . -name "*.sh" -exec chmod 755 {} \; # Ubah semua direktori (tidak termasuk file) find . -type d -exec chmod 755 {} \; # Ubah permission secara selective chmod -R u+rwX,g+rX,o+rX directory/ # Note: X (huruf besar) hanya tambah x ke direktori, bukan file biasa
4. Daftar Pustaka
- ID WebHost. (n.d.). CHMOD: Pengertian, Fungsi, dan Perintahnya. https://tutorial.idwebhost.com
- Jocodev. (2025). Manajemen Paket dan User Permission di Linux. https://jocodev.id
- ID CloudHost. (2024). Mengenal apa itu CHMOD? Pengertian dan Fungsinya. https://idcloudhost.com
- DesdeLinux. (n.d.). Izin Linux untuk Administrator dan Pengembangan Sistem. https://blog.desdelinux.net
- Betariko. (2025). Solusi Error 'Permission Denied' di Linux: Penyebab dan Perbaikannya. https://www.betariko.com

0 Komentar