chmod ve chown, Linux'ta dosya ve dizin izinlerini ve sahipliğini yönetmek için kullanılan temel komutlardır. Güvenlik açısından kritik öneme sahiptirler.
bash
# 755 = rwxr-xr-x
chmod 755 dosya.sh
# 644 = rw-r--r--
chmod 644 dosya.txt
# 700 = rwx------
chmod 700 dosya.sh
# 777 = rwxrwxrwx (tehlikeli!)
chmod 777 dosya.txt
# User + execute
chmod u+x dosya.sh
# Group + write
chmod g+w dosya.txt
# Others - read
chmod o-r dosya.txt
# Recursive
chmod -R 755 dizin/
# Birden fazla
chmod u+x,g+w dosya.sh
# Web sunucusu için
chmod -R 755 /var/www/html/
chmod 644 /var/www/html/*.php
# Script çalıştırma
chmod +x script.sh
# SSH key
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
# Sahip değiştir
chown user dosya.txt
# Sahip:grup değiştir
chown user:group dosya.txt
# Grup değiştir
chown :group dosya.txt
# Recursive
chown -R user:group dizin/
# Referans dosyadan
chown --reference=referans.txt hedef.txt
# Web sunucusu
chown -R www-data:www-data /var/www/html/
# Kullanıcı dizini
chown -R kullanici:kullanici /home/kullanici/
# Docker
chown -R 1000:1000 /var/lib/docker/
chmod — İzin Değiştirme
Sayısal (Octal) Yöntem
| Sayı | Açıklama |
|---|---|
| 4 | Read (r) |
| 2 | Write (w) |
| 1 | Execute (x) |
# 755 = rwxr-xr-x
chmod 755 dosya.sh
# 644 = rw-r--r--
chmod 644 dosya.txt
# 700 = rwx------
chmod 700 dosya.sh
# 777 = rwxrwxrwx (tehlikeli!)
chmod 777 dosya.txt
Sembolik Yöntem
bash# User + execute
chmod u+x dosya.sh
# Group + write
chmod g+w dosya.txt
# Others - read
chmod o-r dosya.txt
# Recursive
chmod -R 755 dizin/
# Birden fazla
chmod u+x,g+w dosya.sh
Yaygın Kullanım Senaryoları
bash# Web sunucusu için
chmod -R 755 /var/www/html/
chmod 644 /var/www/html/*.php
# Script çalıştırma
chmod +x script.sh
# SSH key
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chown — Sahiplik Değiştirme
bash# Sahip değiştir
chown user dosya.txt
# Sahip:grup değiştir
chown user:group dosya.txt
# Grup değiştir
chown :group dosya.txt
# Recursive
chown -R user:group dizin/
# Referans dosyadan
chown --reference=referans.txt hedef.txt
Yaygın Kullanım Senaryoları
bash# Web sunucusu
chown -R www-data:www-data /var/www/html/
# Kullanıcı dizini
chown -R kullanici:kullanici /home/kullanici/
# Docker
chown -R 1000:1000 /var/lib/docker/
🔒 Bu içeriği görmek için giriş yapın