-
三種權限rwx對文件和目錄的不同意義
對文件來說: r:可獲取文件的數據; w:可修改文件的數據;(但不能刪除文件) x:可將此文件運行為進程;(針對二進制文件或腳本) (一般而言,文件默認情況下都不該有執行權限) 對目錄來說: r:可以使用ls獲取其下的所有文件列表;但不能訪問文件,不能cd進目錄,不能查看文件的詳細信息(元數據) w:可修改此目錄下的文件列表;即創建或刪除文件;需要配合x權限來操作 x:可cd至此目錄中,且可使用ls-l來獲取所有文件的詳細屬性信息;可以訪問目錄中的文件
-
umask和acl mask 的區別和聯系
umask命令用來設置限制新建文件權限的掩碼 acl musk 也可以用來限制權限,這是他們的聯系 區別: umask與mask的區別感覺就是mask是給權限設置了一個界限,除了root和文件所有者和other外的其他用戶或者組不能超過他設置的權限界限, 只能低于或者等于。而umask是給定一個模式,只要用戶創建目錄或者文件,其所得到的權限是一定的。
-
三種特殊權限的應用場景和作用
當一個用戶執行一個二進制文件權限不夠時可以用SUID權限。SUID只能運用在二進制可執行文件上,當用戶執行該執行文件時,會臨時擁有該執行文件所有者的權限 當多個用戶屬于同一項目組,或者需要對同一目錄的文件或者子目錄都可以自由操作時,可以用SGID權限。SGID可以應用在目錄或可執行文件上。當SGID應用在文件上時,用戶訪問該文件時執行的是文件所屬組的操作權限。 當SGID應用在目錄上時,該目錄中所有新建立的文件或子目錄的屬組都會是該目錄的屬組 Sticky權限只能應用在目錄,當目錄擁有Sticky所有在該目錄中的文件或子目錄無論是什么權限只有文件或子目錄所有者和root用戶能刪除。
-
設置user1,使之新建文件權限為rw——-
[user1@localhost ~]$ nano /home/user1/.bashrc # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functions umask 066 [user1@localhost ~]$ [user1@localhost ~]$ umask 0066 [user1@localhost ~]$ touch f2 [user1@localhost ~]$ ll f2 -rw------- 1 user1 user1 0 Aug 4 20:26 f2
-
設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫 /testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:— 備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原
[root@localhost ~]# mkdir testdir [root@localhost ~]# touch testdir/f1 [root@localhost ~]# setfacl -m u:user1:0 testdir/f1 [root@localhost ~]# mkdir testdir/dir [root@localhost ~]# groupadd g1 groupadd: group 'g1' already exists [root@localhost ~]# setfacl -m g:g1:rw tsetdir/dir setfacl: tsetdir/dir: No such file or directory [root@localhost ~]# setfacl -m g:g1:rw testdir/dir [root@localhost ~]# setfacl -Rm d:u:user1:rw testdir [root@localhost ~]# setfacl -Rm d:g:g1:0 testdir [root@localhost ~]# touch testdir/f2 [root@localhost ~]# getfacl testdir/f2 # file: testdir/f2 # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r-- [root@localhost ~]# getfacl testdir/f1 # file: testdir/f1 # owner: root # group: root user::rw- user:user1:--- group::r-- mask::r-- other::r-- [root@localhost ~]# getfacl testdir/dir # file: testdir/dir # owner: root # group: root user::rwx group::r-x group:g1:rw- mask::rwx other::r-x default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x [root@localhost ~]# getfacl testdir # file: testdir # 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 [root@localhost ~]# getfacl -R testdir > file.acl [root@localhost ~]# cat file.acl # file: testdir # 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 # file: testdir/f1 # owner: root # group: root user::rw- user:user1:--- group::r-- mask::r-- other::r-- # file: testdir/dir # owner: root # group: root user::rwx group::r-x group:g1:rw- mask::rwx other::r-x default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x # file: testdir/f2 # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r-- [root@localhost ~]# setfacl -R -b testdir [root@localhost ~]# getfacl testdir # file: testdir # owner: root # group: root user::rwx group::r-x other::r-x [root@localhost ~]# setfacl -R --set-file=file.acl testdir [root@localhost ~]# getfacl -R testdir # file: testdir # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r-- default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x # file: testdir/f1 # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r-- # file: testdir/dir # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r-- default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x # file: testdir/f2 # owner: root # group: root user::rw- user:user1:rw- group::r-x #effective:r-- group:g1:--- mask::rw- other::r--
原創文章,作者:dxkboke,如若轉載,請注明出處:http://www.www58058.com/29270