1、基本权限和归属服务器
1. 访问权限ide
读取:容许查看、显示目录列表ui
写入:容许修改,容许在目录中新建、移动、删除文件或子目录spa
可执行:容许运行程序、切换目录对象
2. 查看文件的权限blog
# ls -l install.log继承
-|rw-|r--|r-- 1 root root 26195 Dec 17 10:42 install.log递归
① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩开发
①. 文件类型v8
-表明普通文件
d表明目录
l表明链接
②. rw-:表明文件全部者的权限(u)
r=读=4
w=写=2
x=执行=1
③. r--:表明文件所属组的权限(g)
r=读=4
w=写=2
x=执行=1
④. r--:其余用户的权限(o)
r=读=4
w=写=2
x=执行=1
a=ugo
⑤. 文件 硬连接数
目录 该目录下有多少子目录包括.和..
⑥. 文件全部者
⑦. 文件所属组
⑧. 文件大小
⑨. 文件修改时间
⑩. 文件名
3. 命令 (R表示递归)
chmod 改变权限
chmod ugoa [+-=] [rwx] 文件
chmod 数字 文件
文件最大权限666
目录最大权限777
默认建立文件的权限644
默认建立目录的权限755
umask
最大权限的rwx-umask的rwx=默认权限
补充:
对于目录来讲没有x权限,不管有没rw,都不能进入该目录
chown 改变全部者与所属组
chown 全部者:所属组 对象
chgrp 组 文件更改文件的属组
2、附加权限控制
1. 特殊权限介绍
Set UID:4User+x
Set GID:2Group+x
Sticky Bit:1Other+x
2. 特殊权限做用
Set UID:
只能对可执行程序设置,当其余用户执行带SUID标记的程序时,将会使用程序全部者的身份去执行
Set GID:
能够对可执行程序设置,当其余用户执行带SGID标记的程序时,将会使用程序所属组的身份去执行
能够对目录设置,当对目录设置SGID后,任何人在该目录下建立文件和目录的所属组自动继承该目录的所属组
Sticky Bit:
对目录设置,任何人在该目录下建立文件和目录,只有root与文件建立者有删除权限
3. ACL策略
getfacl文件查看ACL策略
setfacl[选项] u:用户名:权限 文件
setfacl[选项] g:组名:权限 文件
-m定义一条ACL策略
-x删除指定的ACL策略
-b清除全部已设置的ACL策略
-R递归设置
-d为目录设置默认权限
1、基本权限和归属
公司技术部有一台Linux开发服务器,根据部门内项目组的构成状况,须要创建相应的用户帐号,并对开发数据相关目录配置访问权限。
1.文件夹/tech/nsdhome、/tech/jsdhome,分别归属于nsd组、jsd组,禁止其余用户进入。
2.建立部门公共目录/public,技术部的全部员工(tech组)对其拥有可读、可写、可执行,其余用户禁止访问此目录。
[root@localhost /]# mkdir -p /tech/nsdhome
[root@localhost /]# mkdir -p /tech/jsdhome
[root@localhost /]# mkdir /public
[root@localhost /]# groupadd nsd
[root@localhost /]# groupadd jsd
[root@localhost /]# groupadd tech
[root@localhost /]# useradd -g nsd nsd01
[root@localhost /]# useradd -g nsd nsd02
[root@localhost /]# useradd -g jsd jsd01
[root@localhost /]# useradd -g jsd jsd02
[root@localhost /]# useradd -g tech yg01
[root@localhost /]# useradd yg02
[root@localhost /]# chown :nsd /tech/nsdhome
[root@localhost /]# ls -l /tech/nsdhome
总计 0
[root@localhost /]# ls -ld /tech/nsdhome
drwxr-xr-x 2 root nsd 4096 07-30 11:36 /tech/nsdhome
[root@localhost /]# chmod o-rx /tech/nsdhome
[root@localhost /]# chown :jsd /tech/jsdhome
[root@localhost /]# ls -ld /tech/jsdhome
drwxr-xr-x 2 root jsd 4096 07-30 11:36 /tech/jsdhome
[root@localhost /]# chmod o-rx /tech/jsdhome
[root@localhost /]# chown :tech /public
[root@localhost /]# ls -ld /public
drwxr-xr-x 2 root tech 4096 07-30 11:36 /public
[root@localhost /]# chmod g+w /public
[root@localhost /]# ls -ld /public
drwxrwxr-x 2 root tech 4096 07-30 11:36 /public
[root@localhost /]# chmod o-rx /public
[root@localhost /]# ls -ld /public
drwxrwx--- 2 root tech 4096 07-30 11:36 /public
[root@localhost /]# ls -ld /tech/nsdhome
drwxr-x--- 2 root nsd 4096 07-30 11:36 /tech/nsdhome
[root@localhost /]# ls -ld /tech/jsdhome
drwxr-x--- 2 root jsd 4096 07-30 11:36 /tech/jsdhome
[root@localhost /]#
2、附加权限控制
一、Suid实验
只能针对程序(命令)设置,当任何人在执行具备suid权限的命令时,将使用该命令的全部者身份执行
[root@localhost ~]# ls -l /etc/shadow
[root@localhost ~]# which passwd
[root@localhost ~]# ls -l /usr/bin/passwd
[root@localhost ~]# umask 022
[root@localhost ~]# which touch
[root@localhost ~]# cp /bin/tosuuch /bin/suidtouch
[root@localhost ~]# ls -l /bin/*touch
[root@localhost ~]# useradd lily
[root@localhost ~]# su - lily
[lily@localhost ~]$ suidtouch suid-file1.txt
[lily@localhost ~]$ ls -l suid-file1.txt
[lily@localhost ~]$ exit
[root@localhost ~]# ls -l /bin/suidtouch
[root@localhost ~]# chmod u+s /bin/suidtouch
[root@localhost ~]# ls -l /bin/suidtouch
[root@localhost ~]# su - lily
[lily@localhost ~]$ suidtouch suid-file2.txt
[lily@localhost ~]$ ls -l suid-file*
[lily@localhost ~]$ exit
[root@localhost ~]# rm -rf /bin/suidtouch
二、Sgid实验
能对程序(命令)设置,也能够对目录设置
当任何人在执行具备sgid权限的命令时,将使用该命令的所属组身份执行
[root@localhost ~]# which mkdir
[root@localhost ~]# cp /bin/mkdir /bin/sgidmkdir
[root@localhost ~]# ls -l /bin/*mkdir
[root@localhost ~]# su - lily
[lily@localhost ~]$ sgidmkdir test1
[lily@localhost ~]$ ls -ld test1
[lily@localhost ~]$ exit
[root@localhost ~]# chmod g+s /bin/sgidmkdir
[root@localhost ~]# ls -l /bin/sgidmkdir
[root@localhost ~]# su - lily
[lily@localhost ~]$ sgidmkdir test2
[lily@localhost ~]$ ls -ld test*
[lily@localhost ~]$ exit
[root@localhost ~]# rm -rf /bin/sgidmkdir
对目录设置Sgid,任何人在该目录下建立的文件或子目录的所属组都自动继承该目录自己所属组
[root@localhost ~]# mkdir /testgid
[root@localhost ~]# ls -ld /testgid/
drwxr-xr-x 2 root root 4096 Jan 6 16:53 /testgid/
[root@localhost ~]# chmod 0757 /testgid/
[root@localhost ~]# su - lily
[lily@localhost ~]$ mkdir /testgid/lilytest1
[lily@localhost ~]$ touch /testgid/lilyfile1.txt
[lily@localhost ~]$ ls -l /testgid/
[lily@localhost ~]$ exit
[root@localhost ~]# chmod 2757 /testgid/
[root@localhost ~]# ls -ld /testgid/
[root@localhost ~]# su - lily
[lily@localhost ~]$ mkdir /testgid/lilytest2
[lily@localhost ~]$ touch /testgid/lilyfile2.txt
[lily@localhost ~]$ ls -l /testgid/
三、t位权限echo
针对公共目录设置,目录设置t位权限后,该目录下的文件或子目录只有root与文件全部者可以删除
[root@localhost ~]# mkdir /soft
[root@localhost ~]# ls -ld /soft/
[root@localhost ~]# chmod o+w /soft/
[root@localhost ~]# ls -ld /soft/
[root@localhost ~]# useradd wbb
[root@localhost ~]# useradd lhq
[root@localhost ~]# su - lhq
[lhq@localhost ~]$ cat /soft/lhq.txt
hello,byebye
[lhq@localhost ~]$ exit
[root@localhost ~]# su - wbb
[wbb@localhost ~]$ ls -ld /soft/
[wbb@localhost ~]$ ls -l /soft/
[wbb@localhost ~]$ rm -rf /soft/lhq.txt
[wbb@localhost ~]$ ls -l /soft/
[root@localhost ~]# chmod o+t /soft/
[root@localhost ~]# ls -ld /soft/
[root@localhost ~]# su - lhq
[lhq@localhost ~]$ cat /soft/lhq.txt
hello,byebye
[lhq@localhost ~]$ exit
[root@localhost ~]# su - wbb
[wbb@localhost ~]$ ls -l /soft/
[wbb@localhost ~]$ ls -ld /soft/
[wbb@localhost ~]$ rm -rf /soft/lhq.txt
[root@localhost ~]# find / -type f -a -perm +6000//查找系统中suid/sgid的程序
四、ACL权限设置
建立帐户:mike john kaka
建立文件:/data/file1.txt
·mike对文件有读写权限,john只有读权限。其余用户没有任何权限
·kaka具备与john相同权限
·建立lily,lily对file1.txt具备读执行权限,其余用户没有任何权限
[root@localhost ~]# tune2fs -l /dev/sda2 | grep acl
Default mount options: user_xattr acl
[root@localhost ~]# tune2fs -l /dev/sda1 | grep acl
Default mount options: user_xattr acl
[root@localhost ~]# ls -ld /data/
drwxrwxrwx 3 root root 4096 12-09 16:21 /data/
[root@localhost ~]# rm -rf /data/
[root@localhost ~]# mkdir /data
[root@localhost ~]# getfacl /data/
getfacl: Removing leading '/' from absolute path names
# file: data
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
[root@localhost ~]# ls -ld /data/
drwxr-xr-x 2 root root 4096 12-09 16:27 /data/
[root@localhost ~]# setfacl -m u:mike:rwx /data/
[root@localhost ~]# ls -ld /data/
drwxrwxr-x+ 2 root root 4096 12-09 16:27 /data/
[root@localhost ~]# getfacl /data/
getfacl: Removing leading '/' from absolute path names
# file: data
# owner: root
# group: root
user::rwx
user:mike:rwx
group::r-x
mask::rwx
other::r-x
[root@localhost ~]# setfacl -m u:john:r-- /data/
[root@localhost ~]# setfacl -m u:kaka:r-- /data/
[root@localhost ~]# setfacl -m u:lily:r-x /data/