1,當用戶xiaoming 對/testdir 目錄無執行權限時,意味著無法做哪些操作?
先創建目錄/testdir,接著修改目錄的/testdir的權限,用xiaoming的身份去進入/testdir目錄
[root@localhost ~]# mkdir /testdir [root@localhost ~]# ls -ld /testdir drwxr-xr-x 2 root root 4096 Aug 14 06:55 /testdir [root@localhost ~]# chmod o-x /testdir [root@localhost ~]# ll -d /testdir drwxr-xr-- 2 root root 4096 Aug 14 06:55 /testdir [root@localhost ~]# useradd xiaoming [root@localhost ~]# su xiaoming [xiaoming@localhost root]$ cd /testdir bash: cd: /testdir: Permission denied [xiaoming@localhost root]$ ll /testdir ls: cannot access /testdir/file1: Permission denied
上述實驗的結果是:用戶xiaoming對/testdir目錄無執行權限時,利用ls -l 和 cd命令失敗
結論是:當某一用戶對某目錄無執行權限時,是無法利用ls -l命令查看目錄中的文件列表,無法利用cd命令進入該目錄
2,當用戶xiaoming對/testdir 目錄無讀權限時,意味著無法做哪些操作?
接第一題的操作:
[root@localhost ~]# chmod o-r /testdir [root@localhost ~]# ll -d /testdir drwxr-x--x 2 root root 4096 Aug 14 07:00 /testdir [root@localhost ~]# su xiaoming [xiaoming@localhost root]$ ls /testdir ls: cannot open directory /testdir: Permission denied
上述實驗結果是:用戶xiaoming對/tesdir目錄無讀權限時,利用ls 命令失敗
結論是:當某一用戶對某目錄無讀權限時,是無法利用ls 命令查看目錄下的文件列表
3,當用戶xiaoming 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1 是否可修改和刪除?
接第一題的操作:
[root@localhost ~]# chmod o-w /testdir [root@localhost ~]# ll -d /testdir drwxr-xr-x 2 root root 4096 Aug 14 07:00 /testdir [root@localhost ~]# su xiaoming [xiaoming@localhost root]$ cd /testdir [xiaoming@localhost testdir]$ ls file1 [xiaoming@localhost testdir]$ touch test touch: cannot touch `test': Permission denied [xiaoming@localhost testdir]$ rm -f file1 rm: cannot remove `file1': Permission denied
上述實驗結果是:用戶xiaoming對/testdir目錄無寫權限時,利用touch 和rm 命令失敗
結論是:當某一用戶對某目錄無寫權限時,是無法在該目錄下創建新文件和刪除原有文件的
4,復制/etc/fstab 文件到/var/tmp 下,設置文件所有者為xiaoming 讀寫權限,所屬組為sysadmins 組有讀寫權限,其他人無權限
[root@localhost ~]# groupadd sysadmins [root@localhost ~]# cp /etc/fstab /var/tmp [root@localhost ~]# cd /var/tmp [root@localhost tmp]# ll -rw-r--r-- 1 root root 921 Aug 14 07:52 fstab [root@localhost tmp]# chown xiaoming:sysadmins fstab [root@localhost tmp]# chmod ug=rw,o= fstab [root@localhost tmp]# ll fstab -rw-rw---- 1 xiaoming sysadmins 921 Aug 14 07:52 fstab
5,誤刪除了用戶xiaoming 的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性
[root@localhost ~]# cp -r /etc/skel/. /home/xiaoming [root@localhost ~]# cd /home/xiaoming [root@localhost xiaoming]# ls -a . .. .bash_logout .bash_profile .bashrc .gnome2 .mozilla [root@localhost home]# ll -d xiaoming drwxr-xr-x 4 root root 4096 Aug 14 21:59 xiaoming [root@localhost home]# chown -R xiaoming:xiaoming xiaoming [root@localhost home]# ll -d xiaoming drwxr-xr-x 4 xiaoming xiaoming 4096 Aug 14 21:59 xiaoming [root@localhost home]# chmod 700 xiaoming [root@localhost home]# ll -d xiaoming drwx------ 4 xiaoming xiaoming 4096 Aug 14 21:59 xiaoming
6,在/data/testdir 里創建的新文件自動屬于g1 組,組g2 的成員如:alice 能對這些新文件有讀寫權限,組g3 的成員如:tom 只能對新文件有讀權限,
其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾
[root@localhost ~]# mkdir -p /data/testdir [root@localhost ~]# ls -ld /data/testdir drwxr-xr-x 2 root root 4096 Aug 14 22:11 /data/testdir [root@localhost ~]# useradd alice [root@localhost ~]# useradd tom [root@localhost ~]# groupadd g1 [root@localhost ~]# groupadd g2 [root@localhost ~]# groupadd g3 [root@localhost ~]# chgrp g1 /data/testdir [root@localhost ~]# ls -ld /data/testdir drwxr-xr-x 2 root g1 4096 Aug 14 22:11 /data/testdir [root@localhost ~]# chmod g+s /data/testdir [root@localhost ~]# ls -ld /data/testdir drwxr-sr-x 2 root g1 4096 Aug 14 22:11 /data/testdir [root@localhost ~]# gpasswd -g g2 -a alice Adding user alice to group g2 [root@localhost ~]# gpasswd -g g3 -a tom Adding user tom to group g3 [root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir [root@localhost ~]# setfacl -m d:g:g3:r /data/testdir [root@localhost ~]# getfacl /data/testdir getfacl: Removing leading '/' from absolute path names # file: data/testdir # owner: root # group: g1 # flags: -s- user::rwx group::r-x other::r-x default:user::rwx default:group::r-x default:group:g2:rw- default:group:g3:r-- default:mask::rwx default:other::r-x
7,三種權限rwx對文件和目錄的不同意義
對于文件
r:可獲取文件的數據
通常是對文本文件有意義,對二進制文件無意義
w:可修改文件的數據
可清空文件的數據,但不能刪除文件
x:可將次文件運行為進程,普通文件沒有執行權限,也不應該有權限有執行權限,系統默認的
執行權限通常只對可執行文件和腳本
對于目錄:
r:可使用ls命令獲取目錄下的所有文件列表,若想對目錄內的文件進行讀、寫、執行的操作,
則需看文件的對應權限
w:可在此目錄內創建文件,也可以刪除此目錄中的文件
x:可使用ls -l命令查看此目錄中的文件的屬性,可cd進入此目錄
8,umask 和acl mask的區別和聯系
設置了mask后,除所有者其他人以外的用戶和組的facl權限都不能大于mask,可以小于或等于
umask的值是用戶默認創建文件和目錄的權限,默認的文件權限是666-umask的結果,
如果相應位有奇數則要+1,目錄的權限是777-umask的結果
相同點:都是限制用戶的權限
umask限制用戶新建文件或目錄的權限
mask限制除所有者和其他人以外的權限
不同點:所限制權限的程度不同
umask限制用戶的權限位精確到其對應的讀、寫、執行
mask限制除所有者和其他人以外的用戶和組的權限可以小于等于mask,但不能超過mask
9,三種特殊權限的應用場景和作用
Suid只對二進制程序起作用,程序發起者在程序執行的時候繼承程序擁有者的身份以程序擁有者的權限,以程序擁有者的身份去執行程序。
應用場景為root用戶給普通用戶分配需要經常改動的配置文件的修改權限比如密碼passwd.
Sgid作用:對二進制程序的作用與Suid基本一致。對目錄的作用,當目錄設置Sgid時,若用戶在此目錄下所創建的新文件的用戶組與此目錄的用戶組一致。
應用場景:在開發的時候需要將開發的東西共享出來大家都可以隨時加入新成員不用再設置所屬組對共享文件進行查看修改。
Sticky:目錄設置后,所有用戶只能對自己創建的文件進行增刪改查,無法對其他人的文件進行刪除、移動、重命名等操作。
10,設置user1,使之新建文件權限為rw——-
# umask 066 僅對當前shell有效
更改~/.bash 或 ~/.bash_profile 寫入umask 066
11,設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫
[root@localhost testdir]# touch f1 [root@localhost testdir]# ll -rw-r--r-- 1 root root 0 Aug 15 00:04 f1 [root@localhost testdir]# setfacl -m u:user1:0,g:g1:rw f1 [root@localhost testdir]# getfacl f1 # file: f1 # owner: root # group: root user::rw- user:user1:--- group::r-- group:g1:rw- mask::rw- other::r--
12,/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw, g1:—
[root@localhost testdir]# mkdir dir [root@localhost testdir]# setfacl -m d:u:user1:rw,d:g:g1:0 dir [root@localhost testdir]# getfacl dir # file: dir # owner: root # group: root user::rwx group::r-x other::r-x default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x
13,備份/testdir目錄中所有文件的acl,清除/testdir的所有acl權限,并利用備份還原
[root@localhost testdir]# getfacl -R . > /tmp/acl.txt [root@localhost testdir]# setfacl -b -R . [root@localhost testdir]# getfacl -R . [root@localhost testdir]# setfacl -R --set-file=/tmp/acl.txt . [root@localhost testdir]# getfacl -R .
原創文章,作者:pingsky,如若轉載,請注明出處:http://www.www58058.com/29792