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)
上一篇 2016-08-04 14:42
下一篇 2016-08-04 17:40

相关推荐

  • Linux基础知识之WMware Tools的安装

    该博文以CentOS6.8_x86_64系统为基础,tty终端登录CentOS6.8系统,以root身份登录系统。 为什么要安装WMware Tools?                    VMware Tools是VMware虚拟机中自带的一种增强工具,…

    Linux干货 2016-07-29
  • N25-第六周作业

      复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;               s/要查找的内容/替换为的内容/修饰符 %:全文,相当…

    Linux干货 2017-02-13
  • 网络N22期-第五周作业

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@localhost ~]#egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7 /bin/bash 2、找出/etc…

    Linux干货 2016-09-15
  • 2016-08-18作业

    斐波那契数列 fibonacciSequenceFun.sh #!/bin/bash function fibonacci_sequence {   if [ $1 -eq 0 ]; then     echo 0      elif [ $1 -eq 1 ]; then    …

    Linux干货 2016-09-19
  • N26 第七周作业

    1、创建一个10G分区,并格式为ext4文件系统;(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in mem…

    Linux干货 2017-02-07
  • linux 启动管理

    1、Linux系统启动流程:POST 加电自检 — BIOS(Boot Sequence)–>MBR(bootloader,446)(加载前512字节后的驱动程序,进入/boot目录,加载内核)–>Kernel–>initrd–>(系统根路径 /)(ROOTFS)/sbin/…

    Linux干货 2017-09-03