2-本地文件系统安全

概述

  • [x] 使用chmod命令改变文件权限
  • [x] 使用访问控制列表
  • [ ] 在Ubuntu上安装一个LDAP

chmod命令

除了以下的方式外,还可以使用八进制的方式来做权限控制,暂且不表。

命令参数

1
2
3
4
5
6
7
8
u 代表文件或者目录的所有者 users
g 代表文件或者目录所属的组 groups
o 代表文件或者目录外的其他 others
a 代表以上所有 all

r 代表 读
x 代表 执行
w 代表 写

例子

1
2
3
4
5
6
7
8
9
10
11
12
# 新建文件
>> touch test.txt
# 赋予执行的权限
>> chmod u+x test.txt
# 赋予组成员执行权限
>> chmod g+x u+x test.txt
# 收回权限
>> chmod u-x test.txt
# 将某个文件的权限复制给另一个文件
>> chmod --reference=file1 file2
# 递归添加权限
>> chmod o+x -R /example

使用访问控制列表

获取权限控制信息

1
2
3
4
5
6
7
8
linux@linux:~$ getfacl /usr
getfacl: Removing leading '/' from absolute path names
# file: usr
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

操作指南

添加用户+组
1
2
3
4
5
6
7
8
9
10
11
12
useradd user1
useradd user2
useradd user3
passwd -d user1
passwd -d user2
passwd -d user3

addgroup group1

usermod -G group1 user1
usermod -G group1 user2
usermod -G group1 user3
user1 想把文件夹user1 分享给user2,但是不给user3
1
2
3
4
5
6
7
mkdir accounts
chown user1 accounts

su user1
setfacl -m u:user1:rxw accounts
setfacl -m u:user2:rwx accounts
setfacl -m other:--- accounts
实验验证
1
2
3
4
5
6
root@linux:~# su user3
$ cd /example
$ ls
accounts
$ cd accounts
sh: 3: cd: can't cd to accounts
对权限控制做备份
1
2
3
4
$ getfacl -R accounts > accounts/permissions.acl                   
$ cd accounts
$ ls
permissions.acl
恢复备份
1
setfacl -- restore=permission.acl

总结

LADP暂时用不到,先不弄了。