普通文件
d
目錄文件
l
鏈接文件
b
塊設(shè)備文件
c
字符設(shè)備文件
p
管道文件
每個文件都有所有者和所有組,并且有各自的權(quán)限,讀(r)寫(w)執(zhí)行(x),對于文件和目錄rwx含義是不用的
文件:
r 讀取文件內(nèi)容的權(quán)限
w 修改文件內(nèi)容的權(quán)限
x 執(zhí)行文件內(nèi)容的權(quán)限
目錄:
r 查看目錄下文件的權(quán)限
w 穿件、刪除、修改目錄下文件的權(quán)限
r 進入目錄的權(quán)限
示例如下:
lrwxrwxrwx. 1 root root 7 Feb 7 19:53 bin -> usr/bin
dr-xr-xr-x. 3 root root 4096 Feb 7 12:08 boot
文件的特殊權(quán)限
SUID
SUID是一種對二進制程序進行設(shè)置的特殊權(quán)限,可以上二進制程序的執(zhí)行者臨時擁有屬主的權(quán)限(僅對擁有執(zhí)行權(quán)限的二進制程序有效)
命令是chmod u s 文件名,將所有者的權(quán)限由rwx變成rws,其中x變成s表示擁有了SUID權(quán)限,如果原本所有者的權(quán)限是rw-就會變成rwS,其中-會變成大寫的S
例如passwd命令:
[root@localhost /]# ll /bin/passwd
-rwsr-xr-x. 1 root root 27832 Jan 30 2014 /bin/passwd
SGID
SGID主要實現(xiàn)兩種功能:
讓執(zhí)行者臨時擁有屬組的權(quán)限(對擁有執(zhí)行權(quán)限的二進制程序進行設(shè)置)
在某個目錄中創(chuàng)建的文件自動繼承改目錄的用戶組
命令是chmod g s 文件名,將所有組的權(quán)限由rwx變成rws,其中x變成s表示擁有了SGID權(quán)限,如果原本所有組的權(quán)限是rw-就會變成rwS,其中-會變成大寫的S
示例:
創(chuàng)建一個目錄test,屬主和屬組是test,將目錄的權(quán)限設(shè)置為777,其他用戶都可以在test目錄下創(chuàng)建自己的文件,屬主和屬組都是用戶自己
設(shè)置SGID后,其他用戶在test目錄下創(chuàng)建的文件,屬組將會變成test
[root@localhost /]# chmod 777 /test
[root@localhost /]# ls -l /test
drwxrwxrwx. 2 test test 6 Feb 7 20:36 test
[root@localhost /]# su -l developer -c touch /test/a.txt
[root@localhost /]# chmod g s /test
[root@localhost /]# ls -l /test
drwxrwsrwx. 2 test test 6 Feb 7 20:36 test
[root@localhost /]# su -l developer -c touch /test/b.txt
[root@localhost /]# ls -l test/
-rw-r--r--. 1 developer developer 0 Feb 7 20:37 a.txt
-rw-r--r--. 1 developer test 0 Feb 7 20:37 b.txt
SBIT
對一個目錄設(shè)置了SBIT權(quán)限后,改目錄中的文件只能被其所有者執(zhí)行刪除操作,其他用戶沒有刪除權(quán)限。
命令是 chmod o t 目錄名 ,文件的其他人權(quán)限部分的x執(zhí)行權(quán)限會被替換成t或者T,原本有x執(zhí)行權(quán)限則會寫成r,原本沒有x執(zhí)行權(quán)限則會被寫成T。
例如系統(tǒng)中的/tmp目錄,所有用戶都可以在/tmp目錄下創(chuàng)建文件,但是不能刪除其他用戶創(chuàng)建的文件。
文件的隱藏屬性
chattr命令
chattr命令用于設(shè)置文件的隱藏權(quán)限,格式為“chattr [參數(shù)] 文件名” 。如果想要把某個隱藏功能添加到文件上,則需要在命令后面追加 " 參數(shù)" ,如果想要把某個功能移除文件,則需要追加 "-參數(shù)"。命令參數(shù)如下表:
示例:
對一個普通文件進行操作,創(chuàng)建、覆蓋、追加、刪除都是可以的:
[root@localhost ~]# touch aa.txt
[root@localhost ~]# echo hello >aa.txt
[root@localhost ~]# echo hello >>aa.txt
[root@localhost ~]# rm -f aa.txt
對一個文件加上隱藏權(quán)限a,只能追加文件,不能覆蓋和刪除文件
[root@localhost ~]# touch bb.txt
[root@localhost ~]# chattr a bb.txt
[root@localhost ~]# echo hello >bb.txt
-bash: bb.txt: Operation not permitted
[root@localhost ~]# echo hello >>bb.txt
[root@localhost ~]# rm -f bb.txt
rm: cannot remove ‘bb.txt’: Operation not permitted
lsattr 命令
lsattr命令用于顯示文件的隱藏權(quán)限,格式為"lsattr [參數(shù)] 文件"。在linux系統(tǒng)中,文件的隱藏權(quán)限必須使用lsattr命令來查看
[root@localhost ~]# lsattr bb.txt
-----a---------- bb.txt
[root@localhost ~]# ls -l bb.txt
-rw-r--r--. 1 root root 6 Feb 10 11:00 bb.txt
文件訪問控制列表
上面講的一般權(quán)限、特殊權(quán)限、隱藏權(quán)限的一個共性—權(quán)限是針對某一類用戶設(shè)置的,如果想對一個指定的用戶進行單獨的權(quán)限控制,就需要用到文件的訪問控制列表(ACL)。給予普通文件或者目錄設(shè)置ACL其實就是針對指定的用戶或者用戶組設(shè)置文件或者目錄的操作權(quán)限。如果針對某個目錄設(shè)置了ACL,則目錄中的文件會繼承其ACL;如果對文件這事了ACL,則文件不再繼承其所在目錄的ACL。
例如:
使用普通用戶linuxprobe進入root用戶的家目錄中,會提示沒有權(quán)限
[linuxprobe@localhost ~]$ cd /root
-bash: cd: /root: Permission denied
[linuxprobe@localhost ~]$
setfacl 命令
setfacl 命令用戶管理文件的ACL規(guī)則,格式為"setfacl [參數(shù)] 文件名"。文件的ACL提供的是在所有者、所有組、其他人的讀、寫、執(zhí)行權(quán)限之外的特殊權(quán)限控制,使用setfacl命令可以針對單一用戶或用戶組、單一文件或目錄來進行讀、寫、執(zhí)行權(quán)限的控制。針對目錄需要使用 -R 參數(shù);針對文件使用 -m 參數(shù);如果要刪除某一個文件的ACL,則使用 -b 參數(shù)。
示例:
設(shè)置用戶在/root目錄上的權(quán)限,使普通用戶linuxprobe可以進入/root目錄:
[root@localhost ~]# setfacl -Rm u:linuxprobe:rwx /root
[root@localhost ~]# su - linuxprobe
Last login: Mon Feb 10 11:10:08 CST 2020 on pts/2
[linuxprobe@localhost ~]$ cd /root/
[linuxprobe@localhost root]$ ls
anaconda-ks.cfg bb.txt initial-setup-ks.cfg
刪除ACL權(quán)限:
setfacl -b /root
getfacl 命令
getfacl命令用戶顯示文件上設(shè)置的ACL信息,格式為"getfacl 文件名"。
[root@localhost ~]# getfacl /root/
getfacl: Removing leading \\\'/\\\' from absolute path names
# file: root/
# owner: root
# group: root
user::r-x
user:linuxprobe:rwx
group::r-x
mask::rwx
other::---
更多關(guān)于云服務器,域名注冊,虛擬主機的問題,請訪問西部數(shù)碼官網(wǎng):m.ps-sw.cn