權限作業

  • 三種權限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

(0)
dxkbokedxkboke
上一篇 2016-08-05
下一篇 2016-08-05

相關推薦

  • rpm包管理

    linux程序包管理 RPM ================================================================== #ldd 查看二進制程序調用的動態鏈接庫 #ldconfig  -p  顯示本機已緩存的所有可用庫文件     dll: Dynamic…

    Linux干貨 2016-08-18
  • test

    test

    Linux干貨 2016-08-08
  • 文件查找命令

    查找命令:local,find local:非實時查找,通過系統數據庫進行搜索,無法查找到在系統數據庫更新后創建的文件,但是查找速度快,模糊查找(不僅會查找到文件名還會找到文件全路徑) find:在硬盤上進行實時搜索,速度較慢,但是可以找到當前所有的數據 系統數據庫在   /var/lib/mlocate/mlocate.db 系統一般會…

    Linux干貨 2016-08-16
  • 8.4日作業

    1、用正則表達式表示IP地址 ifconfig | grep -E -o "(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}(\<[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]25[0-5]\>)" 5、用正…

    Linux干貨 2016-08-08
  • 循環的特殊用法及函數

    while特殊用法 while read 變量名;do 循環體 done<文件路徑(將文件中的每一行依次讀入循環體,賦值給變量)   (())可以實現C語言風格的變量操作 for循環特殊格式 for((控制變量初始化;條件判斷表達式;控制變量修正表達式)) do 循環體 done 控制變量初始化僅在循環開始時執行一次,進行條件判斷成立后執行循…

    Linux干貨 2016-08-21
欧美性久久久久