#1、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
#2、新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权限
#3、新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup组中
#4、设置helen用户对于/sc和/cw目录可读、可写、可执行
#5、设置/test目录为公共存储目录,对所有用户可以读、写、执行,但用户只能删除属于自己的文件。
#6、在/test/dir里创建的新文件自动属于temp组
以下是使用 Linux 命令完成上述需求的步骤:
1. 创建 g1 组并创建属于 redhat 用户和 g1 组的文件 redhat.txt
groupadd g1
useradd redhat
touch redhat.txt
chown redhat:g1 redhat.txt
操作:
2. 新建 /sc 目录,所属组为 group 组,设置权限
groupadd group
mkdir /sc
chown root:group /sc
chmod 770 /sc
操作:
3. 新建 /cw 目录,设置所属组及权限
groupadd mygroup
mkdir /cw
chown root:mygroup /cw
chmod 770 /cw
chmod g+s /cw # 设置SGID,使新建文件自动属于mygroup组
操作:
4. 设置 helen 用户对 /sc 和 /cw 目录的权限
useradd helen
chown -R helen:helen /sc # 确保helen对/sc目录有操作权限
chown -R helen:helen /cw # 确保helen对/cw目录有操作权限
chmod -R 777 /sc # 赋予helen对/sc目录读写执行权限
chmod -R 777 /cw # 赋予helen对/cw目录读写执行权限
操作:
5. 设置 /test 目录为公共存储目录并设置权限
mkdir /test
chmod 777 /test
chmod +t /test # 设置Sticky Bit权限,用户只能删除自己的文件
操作:
6. 在 /test/dir 里创建的新文件自动属于 temp 组
groupadd temp
mkdir /test/dir
chown root:temp /test/dir
chmod 770 /test/dir
chmod g+s /test/dir # 设置SGID,使新建文件自动属于temp组
操作: