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)
alrenalren
上一篇 2016-08-05
下一篇 2016-08-05

相关推荐

  • 编译安装dropbear

    ssh协议的另一个实现:dropbear 编译安装dropbear [root@centos6 ~]# tar xf dropbear-2013.58.tar.bz2  [root@centos6 ~]# cd dropbear-2013.58 [root@centos6&nbs…

    Linux干货 2016-09-28
  • LAMP+logzilla+sphinx+syslog-ng实现集中日志管理(第一版)[原创]

    一、前言        目前查看系统日志比较被动,遇到系统不正常或故障时才会主动去检查服务器系统日志,这样一来不能及时了解系统的运行情况,因此部署Logzilla+sphine+syslog-ng来弥补这不足。以下为安装、部署平台详细步骤。(Logzilla是什么新东西?其实前身就是php-syslog-ng,引用作者…

    Linux干货 2015-03-27
  • 详解Ntbackup的五种备份方式(下)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/145644 继续上文。   四、差异备份(Differental Backup)     差异备份是…

    Linux干货 2015-03-26
  • N25第三周作业

    一、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@centos01 ~]# who | cut -d " " -f1 | uniq -u root qufudcj 二、取出最后…

    Linux干货 2016-12-26
  • 第8天:脚本基础,btrf,raid,

    http://note.youdao.com/yws/public/redirect/share?id=61b38adef24ced4dc646a5ef8e68df18&type=false

    Linux干货 2016-08-16
  • shell-变量

    bash中变量的种类 根据变量的生效范围等标准:     本地变量:生效范围为当前shell进程;对当前shell之外的其它shell进程,包括当前shell的子shell进程均无效     环境变量:生效范围为当前shell进程及其子进程    …

    Linux干货 2016-08-21