M20-1权限作业

1、当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作?

[root@centos7 testdir]# ls -ld /testdir/
drwxr-xrw-. 3 root root 27 Aug  5 08:38 /testdir/
[root@centos7 testdir]# su xiaoming
[xiaoming@centos7 testdir]$ ls
ls: cannot open directory .: Permission denied
[xiaoming@centos7 testdir]$ cd dir
bash: cd: dir: Permission denied
[xiaoming@centos7 testdir]$ ll /testdir
ls: cannot access /testdir/file: Permission denied
ls: cannot access /testdir/dir: Permission denied
total 0
?????????? ? ? ? ?            ? dir
?????????? ? ? ? ?            ? file
[xiaoming@centos7 testdir]$ rm -rf dir
rm: cannot remove ‘dir’: Permission denied
[xiaoming@centos7 testdir]$ rm -f file
rm: cannot remove ‘file’: Permission denied
[xiaoming@centos7 testdir]$

从上诉实验可知,不能ls查看此目录和目录元数据,不能cd切换到此目录中,也不能删除目录中的文件文件夹
2、当用户xiaoming对/testdir 目录无读权限时,意味着无法做哪些操作?

[root@centos7 testdir]# chmod o=wx /testdir/
[root@centos7 testdir]# ls -ld /testdir/
drwxr-x-wx. 3 root root 27 Aug  5 08:38 /testdir/
[root@centos7 testdir]# su xiaoming
[xiaoming@centos7 testdir]$ ls
ls: cannot open directory .: Permission denied
[xiaoming@centos7 testdir]$ rm -rf file
[xiaoming@centos7 testdir]$ rm -rf dir
rm: cannot remove ‘dir/f1’: Permission denied
rm: cannot remove ‘dir/f2’: Permission denied
[xiaoming@centos7 testdir]$

从上诉实验可知,不能ls查看,但可以删除目录中文件,不能删除目录中的目录及文件

3、当用户wang对/testdir 目录无写权限时,该目录下的只读文件file1是否可修改和删除?

[root@centos7 testdir]# ls -ld /testdir/
drwxr-xr-x. 2 root root 17 Aug  5 13:05 /testdir/
[root@centos7 testdir]# su wang
[wang@centos7 testdir]$ ls
file
[wang@centos7 testdir]$ rm -f file
rm: cannot remove ‘file’: Permission denied
[wang@centos7 testdir]$ echo aaaaa>>file
bash: file: Permission denied
[wang@centos7 testdir]$

从上诉实验可知,不能删除和修改此文件

4、复制/etc/fstab文件到/var/tmp下,设置文件所有者为 wang读写权限,所属组为sysadmins组有读写权限,其他人无权限

[root@centos7 ~]# groupadd sysadmins
[root@centos7 ~]# getent group sysadmins
sysadmins:x:10012:
[root@centos7 ~]# cp /etc/fstab  /var/tmp/
[root@centos7 ~]# chown wang.sysadmins /var/tmp/fstab
[root@centos7 ~]# ll /var/tmp/fstab
-rw-r--r--. 1 wang sysadmins 507 Aug  5 13:11 /var/tmp/fstab
[root@centos7 ~]#

5、误删除了用户wang的家目录,请重建并恢复该用户家目录 及相应的权限属性

[root@centos7 ~]# cp /etc/skel/. /home/wang/ -r
[root@centos7 ~]# cd /home/wang
[root@centos7 wang]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .mozilla
[root@centos7 wang]# cd ../
[root@centos7 home]# ls -ld ./wang
drwxr-xr-x. 3 root root 74 Aug  5 13:13 ./wang
[root@centos7 home]# chown -R  wang.wang ./wang
[root@centos7 home]# chmod 700 ./wang/
[root@centos7 home]# ll
total 12
drwx------. 6 gentoo   gentoo   4096 Aug  4 13:36 gentoo
drwx------. 5 hadoop   hadoop   4096 Aug  3 22:17 hadoop
drwx------. 3 wang     wang       74 Aug  5 13:13 wang
drwx------. 5 xiaoming xiaoming 4096 Aug  5 09:54 xiaoming

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

[root@centos7 ~]# useradd user1
[root@centos7 ~]#
[root@centos7 ~]# su user1
[user1@centos7 root]$ cd
[user1@centos7 ~]$
[user1@centos7 ~]$ vi ~/.bashrc
[user1@centos7 ~]$ umask
0002
[user1@centos7 ~]$ . ~/.bashrc
[user1@centos7 ~]$ umask
0066
[user1@centos7 ~]$ touch file.txt
[user1@centos7 ~]$ ll file.txt
-rw-------. 1 user1 user1 0 Aug  5 13:27 file.txt

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

[root@centos7 testdir]# touch f1
[root@centos7 testdir]# ll
total 0
-rw-r--r--. 1 root root 0 Aug  5 13:34 f1
-rw-r--r--. 1 root root 0 Aug  5 13:05 file
[root@centos7 testdir]# setfacl -m u:user1:0,g:g1:rw /testdir/f1
[root@centos7 testdir]# getfactl /testdir/f1
bash: getfactl: command not found...
[root@centos7 testdir]# getfacl /testdir/f1
getfacl: Removing leading '/' from absolute path names
# file: testdir/f1
# owner: root
# group: root
user::rw-
user:user1:---
group::r--
group:g1:rw-
mask::rw-
other::r--

8、/testdir/dir的权限,使新建文件自动具有acl权限:user1:rw,g1:—

[root@centos7 testdir]# mkdir dir
[root@centos7 testdir]# ll
total 4
drwxr-xr-x. 2 root root 6 Aug  5 13:39 dir
-rw-rw-r--+ 1 root root 0 Aug  5 13:34 f1
-rw-r--r--. 1 root root 0 Aug  5 13:05 file
[root@centos7 testdir]# setfacl -m d:u:user1:rw ./dir/
[root@centos7 testdir]# setfacl -m d:g:g1:0 ./dir/
[root@centos7 testdir]# getfacl ./dir/
# file: dir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:user1:rw-
default:group::r-x
default:group:g1:---
default:mask::rwx
default:other::r-x

9、在/data/testdir里创建的新文件自动属于g1组,组g2的成员如: alice能对这些新文件有读写权限,
组g3的成员如: tom只能对新文件有读权限,其它用户(不属于,g2,g3)不能访问这个文件夹。

[root@centos7 testdir]# rm -rf /data/testdir/
[root@centos7 testdir]#
[root@centos7 testdir]# mkdir -p /data/testdir/
[root@centos7 testdir]# ll /data/testdir/
total 0
[root@centos7 testdir]# ls -ld /data/testdir/
drwxr-xr-x. 2 root root 6 Aug  5 13:44 /data/testdir/
[root@centos7 testdir]# useradd alice
[root@centos7 testdir]# useradd tom
[root@centos7 testdir]# chmod g+s /data/testdir/
[root@centos7 testdir]# ls -ld /data/testdir/
drwxr-sr-x. 2 root root 6 Aug  5 13:44 /data/testdir/
[root@centos7 testdir]# chown .g1 /data/testdir/
[root@centos7 testdir]# ls -ld /data/testdir/
drwxr-sr-x. 2 root g1 6 Aug  5 13:44 /data/testdir/
[root@centos7 testdir]# gpasswd -g g2 -a alice
Adding user alice to group g2
[root@centos7 testdir]# gpasswd -g g3 -a tom
Adding user tom to group g3
[root@centos7 testdir]# setfacl -m d:g:g2:rw /data/testdir/
[root@centos7 testdir]# setfacl -m d:g:g3:r /data/testdir/
[root@centos7 testdir]# getfacl /data/testdir/
getfacl: Removing leading '/' from absolute path names
# file: data/testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-

每天总结博客地址:http://purify.blog.51cto.com/

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

(0)
上一篇 2016-08-05 16:09
下一篇 2016-08-05 16:09

相关推荐

  • 用户组和权限管理的相关命令

    1,useradd  新建用户 useradd -u uid username 创建用户时指定uid(如不指定则Centos:500-60000, Centos7: 1000-60000) -o -u uid username  创建用户时指定uid(可以与已存在用户的uid相同) -g groupname username 创…

    2017-07-25
  • date(时间),timedatectl(时区),cal(日历)的用法

    date+%F 显示日期,   显示格式如 2017-07-15+%T 显示时间    显示格式如 15:00:15+%Y 显示年      显示格式如 2017+%m 月 +%d 日+%H 时+%M 分+%S 秒+%s 从linux初始到现在经历了多少秒+%w 显示数字形式的星期+%a …

    Linux干货 2017-07-14
  • Linux网站架构系列之Mysql—-部署篇

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1321079   MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL所使用的SQL语言是用于…

    Linux干货 2015-04-01
  • Linux基础知识—Vim编辑器/crond周期性任务计划

    vim文本编辑 vim是vi文本编辑的增强版本,因其编辑功能强大、且支持各种语言开发环境关键字自动增亮功能,也可称为是开发工具。在Centos7/RHEL7开始,默认将vi定义成vim –color=auto,已经取代了vi的地位。下面总结下关于vim工具的使用 vim有三种模式,每个模式下有其特定的功能;我们可自由在三者之间切换使用: COMM…

    Linux干货 2016-11-01
  • Python函数式编程指南:目录和参考

    目录: 概述 这一篇简要地描述了函数式编程和一些相关的概念。 函数 这一篇展示了关于函数可能不常用到的部分特征并尝试引导诸位使用函数式的思维解决问题,并介绍了诸多有用的内建函数。 迭代器 这一篇介绍了迭代器以及Python对迭代器的语法级的支持,还包括了内置模块itertools的介绍。 生成器 这一篇介绍了自定义的迭代器——生成器,并展示了生成器的用途和使…

    Linux干货 2015-03-11
  • N26-第七周

    1、创建一个10G分区,并格式为ext4文件系统;   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~]# fdi…

    Linux干货 2017-03-05