0803作业

课上练习

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

 drwxr-xr–. 14 root root 4096 Aug  3 13:35 /testdir

[xiaoming@localhost ~]$ touch /testdir/f1
touch: cannot touch ‘/testdir/f1’: Permission denied                      不能创建
[xiaoming@localhost ~]$ ll /testdir/aa
ls: cannot access /testdir/aa: Permission denied                          不能访问
[xiaoming@localhost ~]$ cd /testdir
-bash: cd: /testdir: Permission denied                                    不能进入
[xiaoming@localhost ~]$ rm /testdir/aa
rm: cannot remove ‘/testdir/aa’: Permission denied                        不能删除

2.当用户xiaoqiang 对/testdir  目录无读权限时,意味着无法做哪些操作?

 drwxr-x-wx. 14 root root 4096 Aug  3 18:24 /testdir

[xiaoqiang@localhost ~]$ cd /testdir
[xiaoqiang@localhost testdir]$ ls
ls: cannot open directory .: Permission denied                        不能看里面文件名
[xiaoqiang@localhost ~]$ echo word > /testdir/x1
[xiaoqiang@localhost ~]$ echo word2 >> /testdir/x1
[xiaoqiang@localhost ~]$ cat /testdir/x1
word
word2
[xiaoqiang@localhost ~]$ rm /testdir/x1
[xiaoqiang@localhost ~]$ rm /testdir/file1
rm: remove write-protected regular file ‘/testdir/file1’? y       
//目录权限w:可以创建或删除目录中文件,配合x(无视文件的权限,因为文件是目录中的内容,一个名字)

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

 drwxr-xr–. 14 root root 4096 Aug  3 18:24 /testdir

 -r–r–r–. 1 root root 0 Aug  3 18:24 file1

[wangcai@localhost ~]$ echo hello > /testdir/file1
-bash: /testdir/file1: Permission denied
[wangcai@localhost ~]$ echo hello >> /testdir/file1           不能修改
-bash: /testdir/file1: Permission denied
[wangcai@localhost ~]$ rm /testdir/file1
rm: cannot remove ‘/testdir/file1’: Permission denied         不能删除

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

[root@localhost ~]# cp /etc/fstab /var/tmp/
[root@localhost ~]# chown wangcai.sysadmins /var/tmp/fstab 
[root@localhost ~]# chmod ug=rw,o= /var/tmp/fstab
[root@localhost ~]# ll /var/tmp/fstab       
-rw-rw----. 1 wangcai sysadmins 465 Aug  3 18:13 /var/tmp/fstab


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

 mkdir /home/wangcai
 cp -r /etc/skel/.[^.]* /home/wangcai
 chmod 700 /home/wangcai/

作业

在/data/testdir 里创建的新文件自动属于g1 组,组g2 的成员如:alice 能对这些新文件有读写权限,组g3 的成员如:

tom 只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹

[root@localhost ~]# mkdir -p /data/testdir 
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# cd /data
[root@localhost data]# chgrp g1 testdir/
[root@localhost data]# chmod 2770 testdir/
[root@localhost data]# ll -d testdir/     
drwxrws---. 2 root g1 6 Aug  3 19:15 testdir/
[root@localhost data]# setfacl -m g:g2:rwx testdir/    //g2组用户能进到testdir目录
[root@localhost data]# setfacl -m g:g3:rwx testdir/    //g3组用户能进到testdir目录
[root@localhost data]# setfacl -m d:g:g2:rw testdir/
[root@localhost data]# setfacl -m d:g:g3:r testdir/
[root@localhost data]# gpasswd -a alice g2
Adding user alice to group g2
[root@localhost data]# gpasswd -a tom g3
Adding user tom to group g3
[root@localhost data]# su alice
[alice@localhost data]$ cd testdir/
[alice@localhost testdir]$ touch f
[alice@localhost testdir]$ getfacl f
# file: f
# owner: alice
# group: g1
user::rw-
group::rwx                      #effective:rw-
group:g2:rw-
group:g3:r--
mask::rw-
other::---

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

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

备份/testdir目录中所有文件的ACL,清除/testdir的所有ACL权限,并利用备份还原

cd /testdir
touch f1
setfacl -m u:user1:0 f1
mkdir dir
setfacl -m g:g1:rw dir
setfacl -m d:u:user1:rw dir
setfacl -m d:g:g1:0 dir 
touch dir/{aa,bb,cc}
getfacl -R dir/ > /bak/bak.acl   
setfacl -R -b *
setfacl -R --set-file=/bak/bak.acl /testdir/dir/

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

[user1@localhost ~]$ umask 0066


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

(0)
victorycommandervictorycommander
上一篇 2016-08-04
下一篇 2016-08-04

相关推荐

  • 第三周作业

    1、列出当前系统上所有已登陆的用户名:          [root@yangjifeng~]# who | cut -d ‘ ‘ -f 1 | sort -u     root 2、取出最后登陆到当前系统的用户信息; &nb…

    Linux干货 2017-08-28
  • 深入理解java嵌套类和内部类

    一、什么是嵌套类及内部类   可以在一个类的内部定义另一个类,这种类称为嵌套类(nested classes),它有两种类型:静态嵌套类和非静态嵌套类。静态嵌套类使用很少,最重要的是非静态嵌套类,也即是被称作为内部类(inner)。嵌套类从JDK1.1开始引入。其中inner类又可分为三种:  其一、在一个类(外部类)中直接定义的内部类;  其二、在一个方法…

    Linux干货 2015-04-07
  • man和history及bashi的快捷键

    man:帮助命令     命令格式:man# cmd;使用时可以先使用whatis 查询所对应的man的章节,然后用对应的man章节来查询帮助;     info:本地帮助文档     官方文档,在线查询等等,如果是付费版系统的话可以使用S…

    Linux干货 2016-07-29
  • N22-℡浮生.若夢 ╮第九周作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash ## declare -i log_user declare -i notlog_user for i …

    Linux干货 2016-12-12
  • 浅谈技术管理(转载,讲的非常不错,技术和产品都值得一看)

      针对这些年旁观和经历过的技术产品场景,做一些个人的总结和判定,尽量不涉及争议性话题,比如对一个互联网公司而言,技术重要还是产品重要之类的,这种话题一扯开,各有道理,谁也别指望说服谁。     此外,加一个前缀,主要针对非技术领导者所面临的技术管理困境,在很多从传统企业转型或个人站转型的互联网企业里,这个问…

    Linux干货 2015-04-04
  • 数据库存储引擎—InnoDB

    MySQL中的数据用各种不同的技术存储在文件(或者内存)中。这些技术中的每一种技术都使用不同的存储机制、索引技巧、锁定水平并且最终提供广泛的不同的功能和能力。通过选择不同的技术,你能够获得额外的速度或者功能,从而改善你的应用的整体功能。

    Linux干货 2018-02-22

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-04 10:36

    每一步都写的很详细,但是能把操作结果总结成一句话就更好的。