檔案許可權管理的拓展
標誌位:-rwsrwxrwx
SUID:當一個檔案帶有suid時,檔案預設加上可執行許可權,且所有人臨時具有管理員權限來執行。
標誌位:-rwxrwsrwx
SGID:當一個目錄檔案帶有sgid時,所有使用者在此目錄下建立檔案的屬組都是此目錄的基本組。
標誌位:-rwxrwxrwt
sticky:當一個目錄檔案帶有sticky時,所有使用者在此目錄中不能刪除屬主不是自己的檔案。
實際應用:
現有2普通使用者redhat和gentoo,想讓他們兩個都能訪問develop檔案夾,且雙方能夠修改彼此建立的檔案,但不能刪除。
解決辦法:
1. 建立檔案develop
mkdir develop
新群組devgrp並把develop的基本組改為此組
groupadd devgrp
chown :devgrp develop
修改檔案夾許可權成-rwxrws—T
chomod 3770 develop #首位3表示兩使用者建立的檔案的屬組都是devgrp,實現他們能夠同構組許可權來相互修改對方的檔案,且不能刪除。
2. 給兩使用者添加附加組devgrp
usermod –aG devgrp redhat
usermod –aG devgrp gentoo
系統預設許可權umask的概念
在不同使用者建立檔案時檔案的許可權是有系統預設設定的:
目錄檔案=777 –umask
普通檔案=666 –umask
如果計算結果為奇數,加一後作為最終許可權(防止產生執行許可權)
檔案的存取控制清單file access control list
實現目的給普通使用者控制訪問自己檔案規則的許可權。
acl添加:
setfacl –m u:使用者名稱:許可權 檔案#給指定使用者添加檔案的許可權
setfacl –m g:組名:許可權 檔案 #給指定組添加檔案的許可權
eg:
# setfacl -m u:student:wrx redhat.c
drwxrwxr-x+ 2 root root 4096 Aug 2 04:11 redhat.c
許可權後加上了“+”號
acl查看:
查看檔案的存取控制清單使用命令getfacl
[root@server28 tmp]# getfacl redhat.c
# file: redhat.c
# owner: root
# group: root
user::rwx
user:student:rwx
group::r-x
mask::rwx
other::r-x
acl的刪除:
[root@server28 tmp]# setfacl -x u:student redhat.c/
刪除對應使用者在該檔案上的acl
[root@server28 tmp]# getfacl redhat.c
# file: redhat.c
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x
刪除所有acl:
[root@server28 tmp]# setfacl -b redhat.c/
[root@server28 tmp]# getfacl redhat.c
# file: redhat.c
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
注意:此時acl mask已被刪除
所謂mask類似子網路遮罩的效果,有它存在所有acl許可權只能小於等於它的許可權
acl mask的設定:
[root@server28 redhat.c]# setfacl -m m::rx test
[root@server28 redhat.c]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:redhat:rwx #effective:r-x 此時系統已經自動給出提示受到mask影響
group::r--
mask::r-x
other::r--
預設acl:
預設acl只對目錄檔案有效,表示對所有在目錄中建立的檔案繼承目錄的acl。
[root@server28 tmp]# setfacl -m d:u:redhat:rwx redhat.c/
[root@server28 tmp]# getfacl redhat.c/
# file: redhat.c
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx #此行往下表示default許可權
default:user:redhat:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
常用的集中壓縮、歸檔程式
gzip 選項 檔案
gzip壓縮檔,且刪除源檔案
選項:
-d 解壓縮
-n 指定壓縮比(1-9)
zcat在不解壓的情況下查看檔案內容
壓縮檔尾碼名:.gz
bzip2 選項 壓縮目的檔案 源檔案(可多個)
bzip2 選項 檔案 (意為壓縮此檔案到目前的目錄)
選項
-d 解壓縮
-k 壓縮時保留源檔案
bzcat在不解壓時查看壓縮包內容
壓縮檔尾碼名 :.bz2
注意:不論是gzip還是bzip2都不支援對文檔的壓縮
tar 選項 壓縮目的檔案 源檔案(可多個可目錄)
壓縮常用的兩種格式
tar zcvf MYFILE.tar.gz source..
z 進行gzip壓縮
c 建立壓縮檔
v 顯示壓縮過程
f 後跟檔案名稱
tar jcvf MYFILE.tar.bz2 source..
j 進行bzip2壓縮
解壓
tar xf 壓縮包[–C 目的路徑]
如不加-C 預設為目前的目錄
注意:tar壓縮時會保留原檔案,且對檔案夾進行歸檔處理後壓縮
本文出自 “Welcome Amigo !” 部落格