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

相关推荐

  • 基于lamp实现wordpress(php-rpm)与phpMyAdmin(pph-rpm+https支持)

    前言    踩了好多坑终于把想象中的样子搭建出来了。真的是,只有遇到问题了,然后扎耳挠腮把问题解决了,才是真的学到了。此次环境我们采用lamp架构,并且通过fastcgi让httpd和php进行通信。当然所有的一切都是在同一台主机上实现。本次安装的应用是phpMyAdmin-4.4.14.1和wordpress-4.3.1

    Linux干货 2016-12-26
  • 基于mysql数据库的日志分析系统

    现如今,日志已经成为了我们分析系统及相关服务的一个重要工具。而日志也具有其相对较为固定的格式以便于进行统计查询。其大致格式如下: 日期时间            主机      &…

    Linux干货 2016-10-23
  • DNS 及 bind的简单配置

    bind的简单配置 摘要:DNS  bind简单配置        FQDN        http://www.178linux.com.  WWW是主机名  .178linux.COM.是私有域名&nbsp…

    Linux干货 2015-10-18
  • 管理SYSTEMd

    核心概念unit,systemctl管理系统服务,

    Linux干货 2018-01-04
  • first

    计算机可分为硬件(CPU ,存储器 ,输入设备 ,输出设备),软件(操作系统 ) 两大部份; CPU:Central Processing Unit 中央处理器 ,内部由运算器,控制器,寄存器,缓存器组成 ; 存储器 :(RAM:Random Access Memory 随机存储器)进行数据 暂存,断电后其内信息会丢失,如内存 ;(ROM:Read Only…

    Linux干货 2016-12-05
  • 一键获取MySQL账户及相关的权限

    有时候,运维同学可能在做grant授权时候,给的用户权限太高了,有风险。因此,我们接手服务器后有必要检查一遍用户权限。 #!/bin/bash# 一键获取MySQL账户及相关的权限 user=’root’ password=’123456′ MYSQL_CMD=’/usr/local/mysql/b…

    Linux干货 2017-05-07