8.3作业

创建sysadmins组 

将user1 user2 user3 加入组中

将user3设置为管理员

用user3登录,将user2从组中移除

设置sysadmins口令centos

设置user1在创建新文件时所属组为sysadmins

删除User1-3

删除sysadmins

[root@localhost testdir]# groupadd sysadmins
[root@localhost testdir]# useradd -G sysadmins user1
[root@localhost testdir]# useradd -G sysadmins user2
[root@localhost testdir]# useradd -G sysadmins user3
[root@localhost testdir]# gpasswd -A user3 sysadmins
[root@localhost ~]# su - user3
[user3@localhost ~]$ gpasswd -d user2 sysadmins
Removing user user2 from group sysadmins
[user3@localhost ~]$ gpasswd sysadmins
Changing the password for group sysadmins
New Password: 
Re-enter new password: 
[root@localhost testdir]# groups user1
user1 : user1 sysadmins
[root@localhost testdir]# usermod -g sysadmins user1
[root@localhost testdir]# groups user1
user1 : sysadmins
[root@localhost testdir]# su - user1
Last login: Thu Aug  4 06:37:20 CST 2016 on pts/0
[user1@localhost ~]$ touch file1
[user1@localhost ~]$ ll file1
-rw-r--r-- 1 user1 sysadmins 0 Aug  4 06:39 file1
[root@localhost testdir]# userdel -r user1
userdel: group user1 not removed because it is not the primary group of user user1.
[root@localhost testdir]# userdel -r user2
[root@localhost testdir]# userdel -r user3
[root@localhost testdir]# groupdel sysadmins

在/data/testdir里创建的新文件自动属于g1组,

组g2的成员如:alice能对这些新文件有读写权限

组g3的成员如:tom只能对新文件有读权限,其他用户(不属于g1,g2,g3)不能访问这个文件

[root@localhost data]# mkdir testdir
[root@localhost data]# groupadd g1
[root@localhost data]# groupadd g2
[root@localhost data]# groupadd g3
[root@localhost data]# chgrp g1 testdir
[root@localhost data]# chmod 2770 testdir
[root@localhost data]# ll
total 0
drwxrws--- 2 root g1 6 Aug  3 23:30 testdir
[root@localhost data]# setfacl -m g:g2:rwx testdir
[root@localhost data]# setfacl -m g:g3:rwx testdir
[root@localhost data]# setfacl -m d:g:g2:rwx testdir
[root@localhost data]# setfacl -m d:g:g3:r testdir
[root@localhost data]# getfacl testdir/
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rwx
default:group:g3:r--
default:mask::rwx
default:other::---

[root@localhost data]# useradd alice
[root@localhost data]# gpasswd -a alice g2
Adding user alice to group g2
[root@localhost data]# su - alice
[alice@localhost testdir]$ touch newfile1
[alice@localhost testdir]$ getfacl newfile1 
# file: newfile1
# owner: alice
# group: g1
user::rw-
group::rwx			#effective:rw-
group:g2:rwx			#effective:rw-
group:g3:r--
mask::rw-
other::---

三种权限rwx对文件个目录的不同意义

文件

r:可使用文件查看类工具获取其内容

w:可修改内容,但不能删除文件本身

x:针对二进制程序或脚本,可以把此文件提请内核启动为一个进程

X:本身没有x权限,将不会增加

目录:

r:可以查看文件列表,但不能访问文件,不能cd进入目录,也不能查看文件的元数据

w:可以创建或删除目录中文件,配合x

x:可以cd进入目录,可以访问目录中文件

X:x等价

umask和 acl mask 的区别和联系

三种特殊权限的应用场景和作用

suid可执行在文件上:启动程序之后,其进程的属主为原程序文件的属主

sgid执行在文件上:启动程序之后,其进程的属主为原程序的属组

sgid执行在目录上:对此目录有写权限的用户在此目录中创建的文件所属的组为此目录的属组

sticky作用在目录上:只有文件的所有者或root可以删除该文件

设置user1,使之新建文件权限为rw——-

[root@localhost testdir]# useradd user1
[root@localhost testdir]# su - user1
[user1@localhost ~]$ umask
0002
[user1@localhost ~]$ umask 177
[user1@localhost ~]$ touch file2
[user1@localhost ~]$ ll file2
-rw------- 1 user1 user1 0 Aug  4 07:23 file2



设置/testdir/f1的权限,使user1用户不可以读写执行,

g1组可以读写/testdir/dir的权限

使新建文件自动具有acl权限:user1:rw,g1:—

备份/testdir目录中所有文件的ACL,清除/testdir的所有ACL权限,并利用备份还原

[root@localhost testdir]# touch f1
[root@localhost testdir]# mkdir dir
[root@localhost testdir]# ll
total 0
drwxr-xr-x 2 root root 6 Aug  4 11:12 dir
-rw-r--r-- 1 root root 0 Aug  4 11:12 f1
[root@localhost testdir]# chmod o-r f1
[root@localhost testdir]# useradd user1
[root@localhost testdir]# su - user1
[user1@localhost ~]$ cd /testdir/
[user1@localhost testdir]$ cat f1
cat: f1: Permission denied
[user1@localhost testdir]$ rm -rf f1
rm: cannot remove ‘f1’: Permission denied
[user1@localhost testdir]$ logout
[root@localhost testdir]# groupadd g1
[root@localhost testdir]# setfacl -m g:g1:rw dir 
[root@localhost testdir]# setfacl -m d:g:g1:0 dir 
[root@localhost testdir]# setfacl -m d:u:user1:rw dir
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
group:g1:rw-
mask::rwx
other::r-x
default:user::rwx
default:user:user1:rw-
default:group::r-x
default:group:g1:---
default:mask::rwx
default:other::r-x

[root@localhost testdir]# getfacl -R dir/ > file123
[root@localhost testdir]# setfacl -R -b dir
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@localhost testdir]# setfacl -R --restore=file123
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
group:g1:rw-
mask::rwx
other::r-x
default:user::rwx
default:user:user1:rw-
default:group::r-x
default:group:g1:---
default:mask::rwx
default:other::r-x

原创文章,作者:DYW,如若转载,请注明出处:http://www.178linux.com/28847

(0)
DYWDYW
上一篇 2016-08-04 14:42
下一篇 2016-08-04 17:40

相关推荐

  • 第四周(1):课堂练习与作业

    课堂练习: 1、删除/etc/grub.conf文件中所有以空白开头的行行首的空白字符 [root@centos6 ~]# sed 's@^[[:space:]]\+@@' /etc/grub.conf 2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符 …

    Linux干货 2016-08-10
  • 文本处理sed的使用

    语法:sed【option】、、、‘script’ inputfile、、、 选项:         -n:不输出模式空间内容到屏幕,即不自动打印        -e: 多点编辑        -f:/PATH/SCRIPT_FILE: 从…

    Linux干货 2017-05-01
  • 探索这个“男人”

    一、前言 正所谓了解一个命令就得了解他的用法,正好是要了解一个人就得了解他的兴趣爱好,处事态度以及为人是怎么样的。 二、man是什么 man – an interface to the on-line reference manuals Man是manual(手册)的缩写,使用权限是所有用户,man命令提供为linux系统在线提供了很好的帮助手册…

    Linux干货 2016-05-03
  • 马哥教育网络班21期+第10周课程练习

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) POST(Power On Self Test): 检测系统外围关键设备(如:CPU、内存、显卡、I/O、键盘鼠标等)是否正常。 加载BIOS(Basic Input and Output System): 根据在BIOS中设置的系统启动顺序来搜索用于启动系统的驱动器(硬盘、光盘、U…

    Linux干货 2016-09-08
  • NoSQL之MongoDB

    分布式系统理论 1、 CAP: 分布式系统只能满足其中两个  Consistency :一致性 Availibility:可用性 Partitions Tolerance :分区容错性 C,A : SQL 传统的数据库。 两段机制。 C,P :悲观枷锁机制,分布式加锁机制。加锁机制与SQL不太一样。 这里的C为最终一致性。 放弃C后的特例,既可以保证可用性,…

    2018-01-09
  • Linux基础之—用户和组管理

    导言:   我们在使用计算机资源时为了资源的合理规划和利用,同时为了实现更好的管理,需要在计算机里有一个使用资源的凭证,这个凭证就是用户,下面就来介绍Linux用户和组管理。 1.资源分派:     资源的分派可以分为三个步骤,分别是    (1)认证(Authertication)   &nbsp…

    Linux干货 2016-08-04