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 08:25
下一篇 2016-08-04 11:48

相关推荐

  • man 命令简单介绍

    man n command man手册页分为下面几个部分: 1 普通命令2 内核提供的系统调用3 库调用4 设备文件5 文件格式规范6 游戏7 杂项8 系统管理命令

    Linux干货 2018-03-03
  • Linux下计划任务神器-Crontab

    作为系统运维人员都清楚,在Linux下定义重复性的任务,我们一般会采用crontab来进行:crontab这个指令所设置的工作将会循环的一直进行下去!可循环的时间为分钟、小时、每日、每月、每周。 crontab计划任务: 1)常见用法:crontab命令的作用和用法如下:描述:为每个用户维护周期性的计划任务文件用法:crontab [-u 用户][-l|-r…

    Linux干货 2016-07-22
  • Openssl——为你的信息保驾护航

    OpenSSL基础 ·传输层协议:TCP,UDP,SCTP         port:进程地址,进程向内核注册使用某端口(独占) ·同一主机上的进程间通信:IPC,message queue,shm,semerphor ·不同主机上的进程间通信:socket  &nbs…

    Linux干货 2016-09-22
  • Nginx配置进阶

    目录 ngx_http_rewrite_module模块 ngx_http_gzip_module模块 ngx_http_fastcgi_module模块 ngx_http_ssl_module模块 ngx_http_referer_module模块 ngx_http_rewrite_module模块 将用户某一次请求的URI当中的字符串是不是能够被我们给出…

    Linux干货 2016-11-05
  • Linux 第一周总结

    一、描述计算机的组成及其功能。 计算机组成是由软件和硬件组成的。 硬件部分由cpu、主板、存储器、输入输出设备组成 Cpu:主要是解释计算机指令以及处理计算机软件中的数据。 主板:是微机最基本的也是最重要的部件之一,一般有BIOS芯片、I/O控制芯片、键和面板控制开关接口、指示灯插接件、扩充插槽、主板及插卡的直流电源供电接插件等元件。 存储器:是存储程序和各…

    2017-07-02
  • 模拟centos6.8系统下initramfs文件和vmlinuz文件损坏恢复

    实验一:关于删除initramfs-2.6.32-642.el6.x86_64.img 文件恢复实验,实验环境centos6.8系统 1.安全起见,请先安排做快照及备份 把initramfs-2.6.32-642.el6.x86_64.img 文件复制一份/root目录下。 [root@centos6: boot]# cp -a initramfs-2.6.…

    2017-05-15

评论列表(1条)

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

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