Salah satu konsep penting di Linux adalah hak akses file.
Setiap file dan direktori di Linux memiliki aturan siapa yang bisa membaca (read), menulis (write), dan menjalankan (execute).
Lihat permission dengan ls -l:
ls -l
Contoh output:
-rwxr-xr-- 1 danang developers 1024 Sep 1 10:00 script.sh
Keterangan:
- → jenis file (- file biasa, d direktori, l symbolic link) rwx → hak owner r-x → hak group r-- → hak other (world) danang → pemilik (owner) developers → grup pemilik chmod u+x script.sh
👉 Tambah execute untuk user (owner).
chmod g-w file.txt
👉 Hapus write dari group.
chmod o+r file.txt
👉 Tambah read untuk other.
r = 4, w = 2, x = 1 Contoh:
chmod 755 script.sh
chmod 644 file.txt
sudo chown danang file.txt
👉 Pemilik file jadi danang.
sudo chown danang:developers file.txt
sudo chgrp developers file.txt
sudo chown -R danang:developers /var/www/html
echo 'echo Hello Linux' > script.sh
chmod 755 script.sh
./script.sh
👉 Script bisa dijalankan oleh semua user, tapi hanya owner yang bisa mengedit.
✅ Gunakan chmod 400 untuk file sensitif (misalnya private key).
✅ Gunakan chmod 700 untuk direktori home user.
✅ Untuk web server: biasanya chmod 755 untuk folder, chmod 644 untuk file.
✅ Jangan asal pakai chmod 777, karena memberikan akses penuh ke semua user → berbahaya.
✅ Rekomendasi permission untuk type directory: find /home/<bebas> -type d -exec chmod 755 {} \;.
✅ Rekomendasi permission untuk type file: find /home/<bebas> -type f -exec chmod 644 {} \;.
chmod untuk mengatur permission file/direktori. chown dan chgrp untuk mengatur kepemilikan. Note: Selalu cek permission dengan
ls -lsetelah mengubah hak akses, untuk memastikan hasilnya sesuai.