Cuma, 27 Şubat 2004

Bu dökümanda sisteme dahil olan ve olmayan kullanıcıların bir dosya üzerinde haklarının nasıl verildiğini/alındığını ve bu dosyanın sahibinin yada grubun nasıl değiştirileceğini anlatacağız. Bu anlatımı görselleştirmek için örnekler sunacağız.
Hakklar nasıl öğrenilir?
Bir klasörde dosyalara verilmiş olan hakları ls -l komutuyla öğrenebiliriz.
|
[anotherUSER@localhost anotherUSER]$ ls -l
insgesamt 16
drwx------ 3 anotherUSER anotherUSER 4096 15. Jan 17:49 Desktop
-rw-rw-r-- 1 anotherUSER anotherUSER 11 15. Jan 17:50 kopya-script
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www1
[anotherUSER@localhost anotherUSER]$ |
Görüldüğü gibi ls -l komutunun çıktısı bize (bu durumda benim /home/ klasörüm) kullanıldığı klasördeki dosyaların hak dağıtımını göstermekte. Tek bir dosyanın hakklarını görebilmek için ls -l komutunu bu dosya üzerinde kullanmalıyız.
Sıradaki örneğimizde önce test isminde bir klasör oluşturup ls -l komutuyla hakklarını gösterip bu klasör içinde test1 ve test2 adlarında iki dosya oluşturacağız. Sonra tekrardan ls -l komutu sayesinde klasör içindeki oluşturduğumuz dosyaların ve tekrardan aynı komut sayesinde tek bir dosyanın hak dağıtımını aldıracağız.
|
[anotherUSER@localhost anotherUSER]$ mkdir test
[anotherUSER@localhost anotherUSER]$ ls -l
insgesamt 20
drwx------ 3 anotherUSER anotherUSER 4096 15. Jan 17:49 Desktop
-rw-rw-r-- 1 anotherUSER anotherUSER 11 15. Jan 17:50 kopya-script
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 18:01 test
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www1
[anotherUSER@localhost anotherUSER]$ cd test/
[anotherUSER@localhost test]$ ls
[anotherUSER@localhost test]$ echo selam bu bir testtir > test1
[anotherUSER@localhost test]$ ls -l
insgesamt 4
-rw-rw-r-- 1 anotherUSER anotherUSER 21 15. Jan 18:01 test1
[anotherUSER@localhost test]$ echo selam buda ikinci bir test > test2
[anotherUSER@localhost test]$ ls -l
insgesamt 8
-rw-rw-r-- 1 anotherUSER anotherUSER 21 15. Jan 18:01 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 28 15. Jan 18:02 test2
[anotherUSER@localhost test]$ ls -l test1
-rw-rw-r-- 1 anotherUSER anotherUSER 21 15. Jan 18:01 test1
[anotherUSER@localhost test]$ |
Görüldüğü gibi test1 dosyasının hak dağılımı -rw-rw-r olarak tanımlı. Bu dağılımın ilk üçlü kombinasyonu ('-rw-') dosyanın sahibinin ikinci üçlü ise ('rw-') gruba dahil olan kullanıcıların üçüncü üçlü ise ('r--) diğer kullanıcıların haklarını göstermekte.
Haklar şu sırayla kullanılır:
-
Dosyanın sahibiysen (bu durumda anotherUSER) rw- haklarına sahipsin
-
Dosyanın grubuna (bu durumda anotherUSER) dahilsen rw- haklarına sahipsin
-
Ne dosyanın sahibi nede grubuna dahil değilsen r-- haklarına sahipsin
Grub değişme
test1 dosyamızın sahibi (ilk yazılı olan isim) anotherUSER, ve dosyamızın grubu (ikinci isim) anotherUSER. Öncelikle test1 dosyamızın grubunu değiştireceğiz. Bu işlem için chgrp (=change group) komutunu kullanacağız. Bir örnekle bu amacımızı gerçekleştirelim.
|
[anotherUSER@localhost test]$ pwd
/home/anotherUSER/test
[anotherUSER@localhost test]$ ls -l
insgesamt 0
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
[anotherUSER@localhost test]$ ls -l test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
[anotherUSER@localhost test]$ chgrp users test1
[anotherUSER@localhost test]$ ls -l
insgesamt 0
-rw-rw-r-- 1 anotherUSER users 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
[anotherUSER@localhost test]$ |
Yukarda önce pwd komutuyla bulunduğumuz klasörü gösterdik, sonra ls -l sayesinde haklara bir bakı verdik, tekrardan ls -l komutu ile test1'in hak dağılımını inceledik. Bu son çıktımıza göre dosyanın sahibi anotherUSER ve grubu anotherUSER. Örneğimizin devamındaysa chgrp users test1 komut kombinasyonunu kullanarak grubu users olarak değiştirdik.
chgrp komutunun kullanımı
chgrp <yeni grubun ismi> <grubun değişecek olan dosya>
bu şekilde olur.
Sahib nasıl değişir?
Sahibi değiştirmek için önce superuser (yani root) haklarına sahib olmalı. Bunu su komutuyla yapabiliriz. Sıradaki örneğimizde chown (=change owner) komutuyla test1 dosyamızın sahibini değiştireceğiz. chown komutunun kullanımı chgrp komutuyla aynı.
Chown komutu
chown <yeni sahibin ismi> <sahibi değişecek dosya>
olarak kullanılır.
|
[anotherUSER@localhost test]$ su
Password:
[root@localhost test]# pwd
/home/anotherUSER/test
[root@localhost test]# ls -l
insgesamt 0
-rw-rw-r-- 1 anotherUSER users 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
[root@localhost test]# ls -l test1
-rw-rw-r-- 1 anotherUSER users 0 15. Jan 18:06 test1
[root@localhost test]# chown unbreak test1
[root@localhost test]# ls -l
insgesamt 0
-rw-rw-r-- 1 unbreak users 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
[root@localhost test]# ls -l test1
-rw-rw-r-- 1 unbreak users 0 15. Jan 18:06 test1
[root@localhost test]# |
Şimdi chown komutunun yaptığına bir göz atalım. Sahibi anotherUSER'den alarak unbreak adındaki kullanıcıya verdi, ve önceden tüm haklarına sahip olan anotherUSER yerine unbreak bu işlemden sonra dosya üzerinde tüm haklara sahip oldu.
Sahib ve grubu kullanıcı numaralarıyla (userid,id) değiştirmek
Genelde linux sistemi kullanımı sistem içinde kolaylaştırmak için her kullanıcıya ve her guruba bir numara verir (uid = user identification). Hak dağılımını biz bu numaralar üzerindende yapabiliriz.
ls -l komutuyla bir dosyanın sadece sahibinin kullanıcı ve grubu ismini gösterebiliyoruz, ama bu komutumuza ek olarak -n eklentisini kullanacağız.
ls -ln (<dosya ismi>)
|
[root@pc05 test]# pwd
/home/anotheruser/test
[root@pc05 test]# ls -l
insgesamt 8
-rw-r--r-- 1 unbreak users 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
[root@pc05 test]# ls -ln
insgesamt 8
-rw-r--r-- 1 507 100 6 Jan 16 08:22 test1
-rw-r--r-- 1 502 502 9 Jan 16 08:22 test2
[root@pc05 test]# chown 502 test1
[root@pc05 test]# ls -ln
insgesamt 8
-rw-r--r-- 1 502 100 6 Jan 16 08:22 test1
-rw-r--r-- 1 502 502 9 Jan 16 08:22 test2
[root@pc05 test]# chgrp 502 test1
[root@pc05 test]# ls -ln
insgesamt 8
-rw-r--r-- 1 502 502 6 Jan 16 08:22 test1
-rw-r--r-- 1 502 502 9 Jan 16 08:22 test2
[root@pc05 test]# ls -l
insgesamt 8
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
[root@pc05 test]# |
yukarda görüldüğü gibi ls -ln komutunun çıktısı bize anotheruser, unbreak ve users 'in uid ve gid'ini ( = group identification) verdi. Anotheruser için 502, unbreak için 507 ve users için 100.
Kullandığımız chgrp ve chown komuıtlarını tekrardan kullandık, yaptığımız tek değişiklik ise isim yerine kullanıcı ve grub numaralarını kullanmamız oldu.
chgrp <yeni gid> <gid'i değişecek olan dosya>
chown <yeni uid> <sahibi değişecek olan dosya>
chmod ile dosya üzerinde hakları tanımlamak
chmod ( = change modus) komutuyla dosyalarımızın haklarını değiştirebilir yada tekrardan adayabiliriz.
|
[anotheruser@pc05 test]$ ls -l
insgesamt 8
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
[anotheruser@pc05 test]$ echo test3 bu kadar > test3
[anotheruser@pc05 test]$ ls -l
insgesamt 12
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rw-r--r-- 1 anotheruser anotheruser 15 Jan 16 10:14 test3
[anotheruser@pc05 test]$ echo test4 olsun > test4
[anotheruser@pc05 test]$ ls -
ls: -: No such file or directory
[anotheruser@pc05 test]$ ls -l
insgesamt 16
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rw-r--r-- 1 anotheruser anotheruser 15 Jan 16 10:14 test3
-rw-r--r-- 1 anotheruser anotheruser 12 Jan 16 10:15 test4
[anotheruser@pc05 test]$ chmod 777 test3
[anotheruser@pc05 test]$ ls -l
insgesamt 16
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rwxrwxrwx 1 anotheruser anotheruser 15 Jan 16 10:14 test3*
-rw-r--r-- 1 anotheruser anotheruser 12 Jan 16 10:15 test4
[anotheruser@pc05 test]$ chmod a+x test4
[anotheruser@pc05 test]$ ls -l
insgesamt 16
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rwxrwxrwx 1 anotheruser anotheruser 15 Jan 16 10:14 test3*
-rwxr-xr-x 1 anotheruser anotheruser 12 Jan 16 10:15 test4*
[anotheruser@pc05 test]$ |
Chmod komutunu kullanırken iki ayrı tarzdan yararlanabiliriz. Yukardaki örneğimizde test3 ve test4 dosyalarını oluşturduk, birini sayılarla olan yöntemle (test3) diğerini ise harflerle kullanılan yöntemle değiştirdik (test4).
Aşağdaki tabelalarda bunları size açıklamaya çalışacağım:
|
rwx |
rwx |
rwx |
rwxrwxrwx |
|
Sahip (u) |
Grub (g) |
Diğerleri (o) |
Herkes (a) |
|
u+x+w+r |
g+x+w+r |
o+x+w+r |
a+x+w+r |
|
7 |
7 |
7 |
777 |
|
Haklar |
Sayılarla |
Harflerle |
|
r |
4 |
r |
|
w |
2 |
w |
|
x |
1 |
x |
Harflerle hak dağıtmak
Harflerle hak dağılımında “a” “-” yada “+” ile “r” (okuma), “w” (yazma) ve “x” (çalıştşrma/açma) kombinasyonuyla haklar verilir.
|
[anotheruser@pc05 test]$ pwd
/home/anotheruser/test
[anotheruser@pc05 test]$ ls -l
insgesamt 8
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rwxrwxrwx 1 anotheruser anotheruser 0 Jan 16 10:16 test3*
-rwxr-xr-x 1 anotheruser anotheruser 0 Jan 16 10:16 test4*
[anotheruser@pc05 test]$ echo bu test5 > test5
[anotheruser@pc05 test]$ ls -l
insgesamt 12
-rw-r--r-- 1 anotheruser anotheruser 6 Jan 16 08:22 test1
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 08:22 test2
-rwxrwxrwx 1 anotheruser anotheruser 0 Jan 16 10:16 test3*
-rwxr-xr-x 1 anotheruser anotheruser 0 Jan 16 10:16 test4*
-rw-r--r-- 1 anotheruser anotheruser 9 Jan 16 12:05 test5
[anotheruser@pc05 test]$ chmod a+x+w test5
[anotheruser@pc05 test]$ ls -l test5
-rwxrwxrwx 1 anotheruser anotheruser 9 Jan 16 12:05 test5*
[anotheruser@pc05 test]$ |
Önce test5 adındaki dosyamızı oluşturduk, sonra
chmod a+x+w test5
ile her bir üçlü gruba (rw- r-- r--) çalıştırma (+x) ve yazma (+w) hakları verdik. Aşağıdaki tabelada bunu açıklayalım şimdi.
|
chmod |
u |
+r |
+w |
+x |
|
--- --- --- |
--- --- --- |
r-- --- --- |
-w- -- -- |
--x --- --- |
|
chmod |
g |
+r |
+w |
+x |
|
--- --- --- |
--- --- --- |
--- r-- --- |
--- -w- --- |
--- --x --- |
|
chmod |
o |
+r |
+w |
+x |
|
--- --- --- |
--- --- --- |
--- --- r-- |
--- --- -w- |
--- --- --x |
|
chmod |
a |
+r |
+w |
+x |
|
--- --- --- |
--- --- --- |
r-- r-- r-- |
-w- -w- -w- |
--x --x --x |
Burda çeşitli kombinasyonlar oluşabilir, mesela chmod a+r+w <dosya> gibi, bunun çıktısı
rw- rw- rw- olur.
Buna göre
|
u |
(user) sahip |
|
g |
(group) grub |
|
o |
(other) diğerleri |
|
a |
(all) herkes |
Bir dosyada sadece sahibe yazma hakkı tanımak isteniliyorsa chmod u+r gruba vermek isteniyorsa yazma hakkı chmod g+r sadece diğer kullanıcılara yazma hakkı verilmesi gerekiyorsa chmod o+r
ve en son olarak her kullanıcıya o dosya üzerinde yaszma hakkı tanınımlamak isteniyorsa
chmod a+r olarak yazılmalı.
Örnekler:
Şimdi test6 ve test7 adında iki dosya daha oluşturalım (burda kullandığım cat > test6 komutu yerine echo (metin) > test6 komutunuda kullanabilirsiniz). Sonra chmod komutumuzla test6 dosyasında önce sahib kullanıcıya (u) dosyayı çalıştırma hakkı (+x) verelim ve aynı zamandada elinden yazma hakkını (-w) alalım.
NOT: Bir hak eklemek için eklenecek gurubu belirledikten sonra eklenecek hakları “+” ile kaldırılacak olanları ise “-” ile gösteriyoruz. Yani örneğimizde “chmod u+x-w <dosya>” olmalı.
Sonra sahibi olan kullanıcıya (u) yazma hakkını (+w) geriye verelim, en son olarakta dosyanın dahil olduğu gruptan (g) yazma hakkını alalım (-w).
|
[anotherUSER@localhost test]$ cat > test6
bu test6 hehe
[anotherUSER@localhost test]$ ls -l
insgesamt 12
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
-rwxrwxrwx 1 anotherUSER anotherUSER 16 16. Jan 18:20 test3
-rwxr-xr-x 1 anotherUSER anotherUSER 10 16. Jan 18:15 test4
-rwxrwxrwx 1 anotherUSER anotherUSER 10 16. Jan 18:15 test5
-rw-rw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
[anotherUSER@localhost test]$ echo buda baska birornek dosya > test7
[anotherUSER@localhost test]$ ls -l
insgesamt 16
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
-rwxrwxrwx 1 anotherUSER anotherUSER 16 16. Jan 18:20 test3
-rwxr-xr-x 1 anotherUSER anotherUSER 10 16. Jan 18:15 test4
-rwxrwxrwx 1 anotherUSER anotherUSER 10 16. Jan 18:15 test5
-rw-rw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
-rw-rw-r-- 1 anotherUSER anotherUSER 26 16. Jan 18:34 test7
[anotherUSER@localhost test]$ ls -l test6
-rw-rw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
[anotherUSER@localhost test]$ chmod u+x-w test6
[anotherUSER@localhost test]$ ls -l test6
-r-xrw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
[anotherUSER@localhost test]$ chmod u+w test6
[anotherUSER@localhost test]$ ls -l test6
-rwxrw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
[anotherUSER@localhost test]$ chmod g-w test6
[anotherUSER@localhost test]$ ls -l test6
-rwxr--r-- 1 anotherUSER anotherUSER 0 16. Jan 18:33 test6
[anotherUSER@localhost test]$ |
Sayılarla modusu değiştimek
Harflerle olan yöntememimiz dışında birde sayılarla olan yöntememimiz var. Burda her bir gurup için belirli bir sayı atamalıyız, bu sayı herhangi bir sayı olmamakta belirli kurallarla ve üçlü bir kombinasyondan oluşan bir sayı olmalı. Anlamayı kolaylaştırmak için bir tabelaya bakalım:
|
r |
4 |
Read (okumak) |
|
w |
2 |
Write (yazmak) |
|
x |
1 |
Execute (çalıştırmak) |
|
- |
0 |
Hiçbir hak |
Şimdi hakları drwxrw-r-x olan bir dosyayı yakından tanıyalım.
|
Hakklar |
Anlamları |
Sayı değerleri |
|
d |
Klasör olduğu başlangıçtaki bu harften belli olur |
yok |
|
Dosyanın sahibinin hakları 4+2+1 = 7 |
|
r |
okuma |
4 |
|
w |
yazma |
2 |
|
x |
çalıştırma |
1 |
|
Dosyanın dahil olduğu grubun hakları 4+2+0 = 6 |
|
r |
okuma |
4 |
|
w |
yazma |
2 |
|
- |
çalıştırma hakkı verilmemiş |
0 |
|
Diger kullanıcıların dosya üstünde hakları 4+0+1 = 5 |
|
r |
okuma |
4 |
|
- |
yazma hakkı verilmemiş |
0 |
|
x |
çalıştırma |
1 |
|
drwxrw-r-x = 765 |
Sayılarla hak dağıtımı daha ayrıntılı olur, çünkü tek bir chmod komutuyla tek seferde dosyanın erişim hakları belirlenebilir. Yukardaki tabelamıza bakacak olursanız ne demek istediğimi daha iyi anlarsınız. r = 4, w = 2, x = 1 haklar dağılımı üç bölümden gerçekleştiğinden her bir bölüm için verilmek istenen hakların sayılarını toplamalı, yani kullanıcı için belirlenmiş rwx erişim izinini 4+2+1 olarak toplamalıyız, sonucu 7 olur. Diğerlerinide toplayacak olursak grubun erişim iyinleri 6 diğer kullanıcıların izinleri 5 olur. Sonuç olarak bu dosyanın erişim izinlerinin
chmod 765 <dosya-ismi>
olarak verildiği görülüyor.
Örnekler:
Şimdi test klasörümüzün içinde yeni bir klasör oluşturalım, adı ornek olsun:
|
[anotherUSER@localhost test]$ pwd
/home/anotherUSER/test
[anotherUSER@localhost test]$ ls -l
insgesamt 12
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
-rwxrwxrwx 1 anotherUSER anotherUSER 16 16. Jan 18:20 test3
-rwxr-xr-x 1 anotherUSER anotherUSER 10 16. Jan 18:15 test4
-rwxrwxrwx 1 anotherUSER anotherUSER 10 16. Jan 18:15 test5
-rwxr--r-- 1 anotherUSER anotherUSER 0 16. Jan 18:37 test6
-rw-rw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:37 test7
[anotherUSER@localhost test]$ mmkdir ornek
[anotherUSER@localhost test]$ ls -l
insgesamt 16
drwxrwxr-x 2 anotherUSER anotherUSER 4096 17. Jan 10:32 ornek
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 15. Jan 18:06 test2
-rwxrwxrwx 1 anotherUSER anotherUSER 16 16. Jan 18:20 test3
-rwxr-xr-x 1 anotherUSER anotherUSER 10 16. Jan 18:15 test4
-rwxrwxrwx 1 anotherUSER anotherUSER 10 16. Jan 18:15 test5
-rwxr--r-- 1 anotherUSER anotherUSER 0 16. Jan 18:37 test6
-rw-rw-r-- 1 anotherUSER anotherUSER 0 16. Jan 18:37 test7
[anotherUSER@localhost test]$ |
Bu yeni klasörümüze girdikten sonra ornek1 ve ornek2 adında iki dosya oluşturalım.
|
[anotherUSER@localhost test]$ cd ornek/
[anotherUSER@localhost ornek]$ echo selam > ornek1
[anotherUSER@localhost ornek]$ echo merhaba > ornek2
[anotherUSER@localhost ornek]$ ls -l
insgesamt 8
-rw-rw-r-- 1 anotherUSER anotherUSER 6 17. Jan 10:36 ornek1
-rw-rw-r-- 1 anotherUSER anotherUSER 8 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ |
Görüldüğü gibi ornek1 dosyamızın hak dağılımı -rw-rw-r-- şeklinde, şimdi bu dosya üzerindeki erişim izinlerini tekrardan dağıtalım. Sahibi olan kullanıcıya ful-izin, gruptaki üyelere okuma ve çalıştırma ve diğerlerine sadece okuma hakkı verelim. Sonuçta şu şekili -rwxr-xr-- almalı.
|
[anotherUSER@localhost ornek]$ ls -l ornek1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek1
[anotherUSER@localhost ornek]$ chmod 754 ornek1
[anotherUSER@localhost ornek]$ ls -l
insgesamt 0
-rwxr-xr-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ |
Burda önce kullanıcının haklarını topladık
okuma için 4 yazma için 2 ve çalıştırma için 1 = 4+2+1 = 7
sonra gruptaki kullanıcılar için hakları topladık
okuma için 4 yazma için 0 ve çalıştırma için 1 = 4+0+1 = 5
enson olarak diğer kullanıcıların değerlerini topladık
okuma için 4 yazma için 0 ve çalıştırma için 0 = 4+0+0 = 4
sonuç 754
bu üçlü kombinasyondan oluşan sayımızı chmod komutuyla dosyamız üzerinde kullandık, ve istediğimiz -rwxr-xr-- sonucuna ulaştık.
Bunu şimdi bir tabelayla daha görsel bir şekilde açıklayalım:
|
|
kullanıcı |
grup |
diğerleri |
|
hakklar |
rwx |
r-x |
r-- |
|
sayılar |
4 2 1 |
4 0 1 |
4 0 0 |
|
toplam (r + w + x) |
4 + 2 + 1 |
4 + 0 + 1 |
4 + 0 + 0 |
|
sonuç |
7 |
5 |
4 |
|
chmod için gerekli parametre |
754 |
Ikinci örneğimizde (ornek2) sahip olan kullanıcıya yazma hakkı gruba dahil kullanıcılara okuma hakkı ve diğer kullanıcılara hiçbir hak tanıyacağız. Yani sonuçtaki hak dağılımı -w-r----- olmalı.
|
[anotherUSER@localhost ornek]$ pwd
/home/anotherUSER/test/ornek
[anotherUSER@localhost ornek]$ ls -l
insgesamt 0
-rwxr-xr-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek1
-rw-rw-r-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ ls -l ornek2
-rw-rw-r-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ chmod 240 ornek2
[anotherUSER@localhost ornek]$ ls -l ornek2
--w-r----- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ ls -l
insgesamt 0
-rwxr-xr-- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek1
--w-r----- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
[anotherUSER@localhost ornek]$ |
[anotherUSER@localhost ornek]$ chmod 240 ornek2
--w-r----- 1 anotherUSER anotherUSER 0 17. Jan 10:36 ornek2
Örnekte görüldüğü gibi chmod için parametremiz busefer 240 oldu. Tekrardan bu örneğimizi tabela aracılığıyla anlamaya çalışalım:
|
|
kullanıcı |
grup |
diğerleri |
|
hakklar |
-w- |
r-- |
--- |
|
sayılar |
0 2 0 |
4 0 0 |
0 0 0 |
|
toplam (r + w + x) |
0 + 2 + 0 |
4 + 0 + 0 |
0 + 0 + 0 |
|
sonuç |
2 |
4 |
0 |
|
chmod için gerekli parametre |
240 |
Chmod komutunun sonuna geldik, umarım anlatmaya çalıştığım bu komutu size aktarabilmişimdir, son olarak (aslında chmod'un başında belirtmeliydim) bu komutu sadece dosyanın sahibinin ve root kullanıcının bir dosya üzerinde kullanabileceğini söylemek düşüyor.
Klasör ve klasör içindeki dosyalara tek komut ile aynı hakları adamak ( -R)
Diyelim mesela elimizde 'mart' adında bir klasör var, bu klasöre ve içindeki tüm dosyalara aynı hakları vermek istiyoruz. Şimdi tabiki klasörün içine geçerek her dosyayı birer birer değiştirmek uzun süreceğinden alternatif bir yol bulmalıyız, bu basit işlemi gerçekleştirmek için tekeri tekrardan icat etmek zorunda değiliz, çünkü yukarda tanıttığımız komutların bir ortak özelliği var, bir klasöre ve bunun içindeki tüm dosyalara ve klasörlere '- R' parametresiyle aynı hakları tek bir işlemle verebiliriz. Bu parametreyi bir örnekle pekinleştirelim:
|
[anotherUSER@localhost anotherUSER]$ ls
Desktop kopya-script proje2.tar.bz2 projekt test www www1
[anotherUSER@localhost anotherUSER]$ mkdir mart
[anotherUSER@localhost anotherUSER]$ cd mart/
[anotherUSER@localhost mart]$ echo selam > dunya
[anotherUSER@localhost mart]$ mkdir mart2
[anotherUSER@localhost mart]$ cd mart2/
[anotherUSER@localhost mart2]$ echo selam2 > dunya2 |
Önce mart adında bir klasör oluşturduk, bu klasörün içinde dunya adında bir dosya ve mart2 adında bir klasör oluşturduk, sonra mart2 klasörünün içinde dunya2 adında bir dosya daha oluşturduk.
|
[anotherUSER@localhost mart2]$ ls -l
insgesamt 4
-rw-rw-r-- 1 anotherUSER anotherUSER 7 15. Feb 19:58 dunya2
[anotherUSER@localhost mart2]$ cd ..
[anotherUSER@localhost mart]$ ls -l
insgesamt 8
-rw-rw-r-- 1 anotherUSER anotherUSER 6 15. Feb 19:57 dunya
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Feb 19:58 mart2
[anotherUSER@localhost mart]$ cd ..
[anotherUSER@localhost anotherUSER]$ ls -l
insgesamt 72
drwx------ 3 anotherUSER anotherUSER 4096 17. Jan 12:01 Desktop
-rw-rw-r-- 1 anotherUSER anotherUSER 11 15. Jan 17:50 kopya-script
drwxrwxr-x 3 anotherUSER anotherUSER 4096 15. Feb 19:57 mart
-rwxrwxr-x 1 anotherUSER anotherUSER 43905 16. Jan 18:12 proje2.tar.bz2
drwxr-xr-x 3 anotherUSER anotherUSER 4096 14. Feb 08:31 projekt
drwxrwxr-x 3 anotherUSER anotherUSER 4096 17. Jan 10:32 test
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www1 |
Sonra ls -l komutuyla dosyalarımızın ve klasörümüzün hak dağılımlarına bir göz attık.
|
[anotherUSER@localhost anotherUSER]$ chmod -R 777 mart/
[anotherUSER@localhost anotherUSER]$ ls -l
insgesamt 72
drwx------ 3 anotherUSER anotherUSER 4096 17. Jan 12:01 Desktop
-rw-rw-r-- 1 anotherUSER anotherUSER 11 15. Jan 17:50 kopya-script
drwxrwxrwx 3 anotherUSER anotherUSER 4096 15. Feb 19:57 mart
-rwxrwxr-x 1 anotherUSER anotherUSER 43905 16. Jan 18:12 proje2.tar.bz2
drwxr-xr-x 3 anotherUSER anotherUSER 4096 14. Feb 08:31 projekt
drwxrwxr-x 3 anotherUSER anotherUSER 4096 17. Jan 10:32 test
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www
drwxrwxr-x 2 anotherUSER anotherUSER 4096 15. Jan 17:49 www1
[anotherUSER@localhost anotherUSER]$ cd mart/
[anotherUSER@localhost mart]$ ls -l
insgesamt 8
-rwxrwxrwx 1 anotherUSER anotherUSER 6 15. Feb 19:57 dunya
drwxrwxrwx 2 anotherUSER anotherUSER 4096 15. Feb 19:58 mart2
[anotherUSER@localhost mart]$ cd mart2/
[anotherUSER@localhost mart2]$ ls -l
insgesamt 4
-rwxrwxrwx 1 anotherUSER anotherUSER 7 15. Feb 19:58 dunya2
[anotherUSER@localhost mart2]$ |
Şimdiyse 'chmod -R 777 mart/' komutuyla mart/ ve içinde bulunan her dosyaya aynı hakları verdik, ve bunu tekrardan ls -l komutunu kullanarak gösterdik.
Bu anlatımım burda sona erdi, eğer eklenecek bişey varsa bunu ya bana anotheruser@linuxq.org yada Murat arkadaşımıza murat@linuxq.org belirtmenizi rica ederim, lütfen sorularınızı http://www.trlinux.lug.org.uk/forum adresinde bulunan lapis-forumunda sorunuz.
Saygılarla,
Aytaç Kırmızı |