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

相关推荐

  • 关于 文本处理工具、正则表达式、grep 的简单举例

                              文本处理工具 抽取文本的工具 文件内容:less和cat 文件截取:head和tail 按列抽取:cut 按关键字抽取:grep 文件查看命令:cat,tac,rev cat […

    系统运维 2016-08-08
  • 实现基于MYSQL验证的vsftpd虚拟用户

    马哥教育面授21期 运维 vsftpd MySQL 说明:本实验在两台CentOS主机上实现,一台做为FTP服务器,一台做数据库服务器 一、安装所需要包和包组: 在数据库服务器上安装包: yum –y install mariadb-server mariadb-devel systemctl start mariad…

    Linux干货 2016-12-21
  • redis

    redis 简述 redis的数据结构 redis的数据持久化实现 程序与配置文件 redis-cli命令 主从复制原理与架构实现 redis的高可用方案 – sentinel redis分布式系统概述与简介 简述 什么是redis? redis是一个基于nosql技术的kv数据库,支持非常大的并发场景,与memcached不同的是,redis拥…

    Linux干货 2016-08-19
  • 优云携手网易云 助力企业“互联网+”转型

    12月16日,网易旗下“网易云”首届“网易云聚,共创未来”合作伙伴大会在网易杭州园区举行,优云(uyun.cn)成为首批授牌20家企业之一,并作为核心合作伙伴代表现场签署了合作伙伴协议。 右二为优云软件运营经理 柴勇 现场签署合作伙伴协议 会上,网易杭州研究院执行院长汪源介绍了网易云的战略生态全境,提出“产品体系+培训体系+服务体系”的网易云三大核心竞争力,…

    Linux资讯 2017-03-15
  • “拆”解RAID工作原理

    一、什么是RAID RAID:Redundant Arrays of Inexpensive(Independent)Disks,廉价(独立)的冗余磁盘阵列。1988年由加利福尼亚大学伯克利分校提出。使用多个相对便宜的磁盘通过某种方式组合成一个“阵列”,来提供更好的性能、冗余,或两者同时提供。 性能提高:     &n…

    Linux干货 2016-11-22
  • 帮助和文件管理信息

    history命令: -c 清空命令历史 -d offset 删除历史中指定的第offset个命令 n 显示最近的n条历史 -a 追加本次会话新执行的命令历史列表至历史文件 -n 读历史文件中未读过的行到历史列表 -r 读历史文件附加到历史列表 -w 保存历史列表到指定的历史文件 -p 展开历史参数成多行,但不存在历史列表中 -s 展开历史参数马一行。附加在…

    Linux干货 2017-04-11