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

相关推荐

  • linux的发展史

    一、今天要介绍的Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。 但是很多时候我们了解到的技术都不是…

    Linux干货 2016-10-17
  • 马哥教育网络班21期+第4周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 # cp -a /etc/skel /home/tuser1 # chmod -R g-rwx,o-rwx /home/tuser1/ 2、编辑…

    Linux干货 2016-07-16
  • 编译安装LAMP-centos7

    编译安装LAMP (centos7 基于模块化) 编译安装所需版本 Httpd 2.4,PHP 5.4,MariaDB 5.5通用二进制格式(绿色安装包) MAriDB5.5 绿色安装 1、#mkdir lamp :创建一个文件夹,存放软件的版本 2、从官网上下载httpd2.4 mariaDb 5.5 PHP 5.4到该文件夹下 3、# tar xvf m…

    Linux干货 2017-05-17
  • 马哥教育网络班21期+第3周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d' ' -f1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 [ro…

    Linux干货 2016-07-29
  • ☞磁盘管理、MBR、GPT、分区工具、文件系统、常见分区挂载

    磁盘管理{磁盘结构;MBR;GPT;分区工具;文件系统;分区挂载;}

    Linux干货 2016-08-29
  • ansible实践

    本偏文章以上图拓扑部署 首先准备了6台为centos7的主机(确保selinux和iptables不会成阻碍!关闭他们) 我们先来安装ansible吧! 配置EPEL源过后使用 yum -y install ansible  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 出师不利啊,安装ansible就失败了。!!!!!! 看了一下…

    Linux干货 2017-01-27