文件權限設置: 可以賦于某個用戶或組 能夠以何種方式 訪問某個文件
rw-r--r-- alice hr install.log權限對象:屬主: u屬組: g其他人: o權限類型:讀:r 4寫:w 2執行: x 1設置權限1. 更改文件的屬主、屬組chown:[root@localhost ~]# chown alice.hr file1 //改屬主、屬組[root@localhost ~]# chown alice file1 //只改屬主[root@localhost ~]# chown .hr file1 //只改屬組[root@localhost ~]# chown -R alice.hr dir1 chgrp:[root@localhost ~]# chgrp it file1 //改文件屬組[root@localhost ~]# chgrp -R it dir1//改文件屬組2. 更改權限a. 使用符號對象 賦值符 權限類型u + rchmod g - w file1o = xa[root@localhost ~]# chmod u+x file1 //屬主增加執行[root@localhost ~]# chmod a=rwx file1 //所有人等于讀寫執行[root@localhost ~]# chmod a=- file1 //所有人沒有權限[root@localhost ~]# chmod ug=rw,o=r file1 //屬主屬組等于讀寫,其他人只讀[root@localhost ~]# ll file1 //以長模式方式查看文件權限-rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //顯示的結果b. 使用數字[root@localhost ~]# chmod 644 file1[root@localhost ~]# ll file1-rw-r--r-- 1 alice it 17 10-25 16:45 file1
[root@localhost tmp]# ll -d dir1drwxrwxrwx 3 jack gougou 4096 7月 22 04:12 dir1[root@localhost tmp]# ll dir1總用量 4drwxr-xr-x 2 root root 4096 7月 22 04:12 dir100-rw-rw-rw- 1 jack gougou 0 7月 22 03:54 file1-rw-rw-rw- 1 jack gougou 0 7月 22 03:54 file2[root@localhost tmp]# chmod -R a=rwX dir1[root@localhost tmp]# ll -d dir1drwxrwxrwx 3 jack gougou 4096 7月 22 04:12 dir1[root@localhost tmp]# ll dir1總用量 4drwxrwxrwx 2 root root 4096 7月 22 04:12 dir100-rw-rw-rw- 1 jack gougou 0 7月 22 03:54 file1-rw-rw-rw- 1 jack gougou 0 7月 22 03:54 file2
[root@localhost ~]# ll /home/總用量 24drwx------ 4 alice alice 4096 7月 22 00:11 alicedrwx------ 4 jack jack 4096 7月 22 19:34 jackdrwx------. 2 root root 16384 7月 11 23:44 lost+found[root@localhost ~]# chgrp hr /home/jack/[root@localhost ~]# ll /home/總用量 24drwx------ 4 alice alice 4096 7月 22 00:11 alicedrwx------ 4 jack hr 4096 7月 22 19:34 jackdrwx------. 2 root root 16384 7月 11 23:44 lost+found[root@localhost ~]# id jackuid=500(jack) gid=500(jack) 組=500(jack)[root@localhost ~]# su - jack[jack@localhost ~]$ touch file1[jack@localhost ~]$ ll總用量 0-rw-rw-r-- 1 jack jack 0 7月 22 19:40 file1[jack@localhost ~]$ logout[root@localhost ~]# useradd robin -g hr[root@localhost ~]# id robinuid=502(robin) gid=505(hr) 組=505(hr)[root@localhost ~]# ll /home/robin/總用量 0[root@localhost ~]# ll /home/robin/ -ddrwx------ 4 robin hr 4096 7月 22 19:41 /home/robin/[root@localhost ~]# su - robin[robin@localhost ~]$ touch file1[robin@localhost ~]$ ll file1 -rw-r--r-- 1 robin hr 0 7月 22 19:42 file1
x----------cd
r權限驗證
[root@localhost tmp]# touch file[root@localhost tmp]# ll file -rw-r--r-- 1 root root 0 7月 22 07:25 file[root@localhost tmp]# echo 111 > file[root@localhost tmp]# cat file 111[root@localhost tmp]# su - alice[alice@localhost ~]$ cat /tmp/file 111[alice@localhost ~]$ echo 222 >> /tmp/file-bash: /tmp/file: Permission denied[alice@localhost ~]$ logoutx權限驗證
[root@localhost tmp]# mkdir dir100[root@localhost tmp]# ll -d dir100/drwxr-xr-x 2 root root 4096 7月 22 07:32 dir100/[root@localhost tmp]# chmod o=x dir100/[root@localhost tmp]# ll -d dir100/drwxr-x--x 2 root root 4096 7月 22 07:32 dir100/[root@localhost tmp]# su - alice[alice@localhost ~]$ cd /tmp/dir100/[alice@localhost dir100]$ lsls: cannot open directory .: Permission denied
r權限驗證[root@localhost tmp]# chmod o=r dir100/[root@localhost tmp]# touch dir100/file1[root@localhost tmp]# touch dir100/file2[root@localhost tmp]# ll -d dir100/drwxr-xr-- 2 root root 4096 7月 22 07:33 dir100/[root@localhost tmp]# su - alice[alice@localhost ~]$ cd /tmp/dir100/-bash: cd: /tmp/dir100/: Permission denied[alice@localhost ~]$ ls /tmp/dir100/ls: cannot access /tmp/dir100/file1: Permission deniedls: cannot access /tmp/dir100/file2: Permission deniedfile1 file2[alice@localhost ~]$ logout[root@localhost tmp]# chmod o=rx dir100/[root@localhost tmp]# su - alice[alice@localhost ~]$ cd /tmp/dir100/[alice@localhost dir100]$ lltotal 0-rw-r--r-- 1 root root 0 Jul 22 07:33 file1-rw-r--r-- 1 root root 0 Jul 22 07:33 file2
新聞熱點
疑難解答