用户和文件权限管理命令的使用(实验)

需求概述:

1,建立用户目录
创建目录 /tech/it 和 /tech/development ,分别用于存放各项目组中用户账号的宿主目录。
[root@localhost ~]# mkdir -p /tech/it
[root@localhost ~]# mkdir -p /tech/development
例如:zhangsan 用户的宿主目录应位于 /tech/development/zhangsan
[root@localhost development]# useradd -d /tech/development/zhangsan zhangsan

2,添加组账号
为两个项目组添加组账号 it , development,GID分别设置为1101,1102。
[root@localhost ~]# groupadd -g 1101 it
[root@localhost ~]# groupadd -g 1102 develoment
为技术部添加组账号 tech ,GID 设置为 1100
[root@localhost ~]# groupadd -g 1100 tech
3,添加用户账号
it 组包括三个用户,jack, rose, tom 宿主目录均使用 /tech/it 目录中与账号同名的文件夹
[root@localhost ~]# useradd -g 1101 -d /tech/it/jack jack
[root@localhost ~]# useradd -g 1101 -d /tech/it/rose rose
[root@localhost ~]# useradd -g 1101 -d /tech/it/tom tom
其中 jack 用户账号设置为 2021年10月1日失效
[root@localhost ~]# usermod -e 2021-10-1 jack
development 组中包括两个用户,分别是 zhangsan 和 lisi 宿主目录均使用 /tech/development
[root@localhost ~]# useradd -d /tech/development/lisi -g 1102 lisi
[root@localhost ~]# usermod -g 1102 zhangsan
目录中与账号同名的文件夹。其中 zhangsan 用户的登录shell设置为 /bin/sh
[root@localhost ~]# usermod -s /bin/sh zhangsan
上述所有的用户账号均要求加入到 tech 组内
[root@localhost ~]# usermod -G 1100 jack
[root@localhost ~]# usermod -G 1100 rose
[root@localhost ~]# usermod -G 1100 tom
[root@localhost ~]# usermod -G 1100 zhangsan
[root@localhost ~]# usermod -G 1100 lisi
在测试阶段仅为 jack, rose, zhangsan 这三个用户账号设置初始密码 “123456” ,其它用户暂时先不设置密码。
[root@localhost ~]# passwd jack
Changing password for user jack.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd rose
Changing password for user rose.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd zhangsan
Changing password for user zhangsan.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
4,设置目录权限和归属
将 /tech 目录的属组设置为 tech ,去除其它用户的所有权限
[root@localhost ~]# chown :tech /tech/
[root@localhost ~]# chmod o= /tech/
将 /tech/it 目录的属组设置为 it ,去除其它用户的所有权限
[root@localhost ~]# chown :it /tech/it/
[root@localhost ~]# chmod o= /tech/it/
将 /tech/development 目录的属组设置为 development ,去除其它用户的所有权限
[root@localhost tech]# chown :develoment development
[root@localhost tech]# chmod o= development/
5,建立公共数据存储目录
创建 /public 目录,允许所有技术组内的用户读取,写入,执行文件,非技术组的用户禁止访问此目录。
[root@localhost ~]# mkdir /public
[root@localhost ~]# chown :tech /public/
[root@localhost ~]# chmod 070 /public/
且 /public 目录仅允许 root 用户删除。
[root@localhost ~]# chmod a+t /public/
6,在 /public 目录内创建文件 attendance ,仅允许在此文件中追加内容,不允许覆盖/删除内容。
[root@localhost ~]# mkdir -p /public/attendance
[root@localhost ~]# chattr +a /public/attendance/
7,创建目录 /finance ,允许root 用户具有读写权限,其它人没有任何权限。
[root@localhost ~]# mkdir /finance
[root@localhost ~]# chmod 600 /finance/
特别允许用户 caiwu 对此目录具有全部权限。
[root@localhost ~]# useradd caiwu
[root@localhost ~]# passwd caiwu
Changing password for user caiwu.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# setfacl -m u:caiwu:rwx /finance/
[root@localhost ~]# getfacl /finance/
getfacl: Removing leading '/' from absolute path names
# file: finance/
# owner: root
# group: root
user::rw-
user:caiwu:rwx
group::---
mask::rwx
other::---

作者:赵世渊

-------------------------------------------

个性签名:独学而无友,则孤陋而寡闻。

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

原文地址:https://www.cnblogs.com/Raphel/p/13891611.html