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

相关推荐

  • N22-浙江-情歌第一周博客作业

    一、计算机的组成及其功能    计算机有五大组成部分:CPU(控制器和运算器)、内存、输入、输出           CPU:运算、控制、寄存、缓存功能           内存:RAM       &nbsp…

    Linux干货 2016-08-15
  • 命令,Linux的独特魅力

    转眼又学了一个星期,那就来分享一下这个星期所学的知识吧! 这个星期学的都是各种命令,而这些命令就如同windoes里面画面上的各种选项,没有这些命令,那么你对它将无从下手。那下面就来看看这些命令的强大功能 help   man help(内部命令帮助),等同于man(外部命令帮助)。当你对一个命令不熟悉时,这两个命令将是你的救命符 选定一个命令,先…

    2017-07-22
  • CentOS 7, lamp (php-fpm);(Blog 15)

    要求:
    (1) 三者分离于三台主机;
    (2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
    (3) xcache

    2017-12-20
  • 第一周学习总结

    俗话说,好记性不如烂笔头,在当今移动互联网横行的时代,烂笔头就是网络,而笔记本就是各种平台。 作为一个IT人,有人突然问你计算机是啥,你可能不会像学文科的人一样给他说,就是电脑啊。这时候就是凸显IT知识技能的时候了,那么我下面就给您慢慢的道来。 在1946年美籍匈牙利人冯·诺依曼首次提出了自己的计算机体系理论,简称冯·诺依曼体系,主要是说计算机由五大基本部件…

    2017-12-14
  • 自动化运维跟安全配置

    安全相关工具rpm -qf /usr/bin/sshopenssh semanage port -a -t ssh_port_t -p tcp #PORTNUMBER/端口9527修改ssh的默认端口,ssh默认只能用22端口多台主机互联免口令1 ssh-keygen三台主机各自生成私钥公钥2 ssh-copy-id IP7三台主机各自复制公钥到同一台主机3…

    2018-02-06
  • Python高阶函数和装饰器

    高阶函数 First Class Object 函数在Python中是一等公民 函数也是对象,可调用(callable)的对象 函数可以作为普通变量、参数、返回值等等 高阶函数 数学概念y=g(f(x)) 在Python中,高阶函数应该满足下列至少一个条件 接受一个或者多个函数作为参数 输出一个函数 计数器 def counter(base): def in…

    Linux干货 2017-10-23