8月3号 用户权限作业

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

  先创建目录/testdir,接着修改目录的/testdir的权限,用xiaoming的身份去进入/testdir目录

[root@localhost ~]# mkdir /testdir
[root@localhost ~]# ls -ld /testdir
drwxr-xr-x 2 root root 4096 Aug 14 06:55 /testdir
[root@localhost ~]# chmod o-x /testdir
[root@localhost ~]# ll -d /testdir
drwxr-xr-- 2 root root 4096 Aug 14 06:55 /testdir
[root@localhost ~]# useradd xiaoming
[root@localhost ~]# su xiaoming
[xiaoming@localhost root]$ cd /testdir
bash: cd: /testdir: Permission denied
[xiaoming@localhost root]$ ll /testdir
ls: cannot access /testdir/file1: Permission denied

上述实验的结果是:用户xiaoming对/testdir目录无执行权限时,利用ls -l 和 cd命令失败

结论是:当某一用户对某目录无执行权限时,是无法利用ls -l命令查看目录中的文件列表,无法利用cd命令进入该目录

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

  接第一题的操作:

[root@localhost ~]# chmod o-r /testdir
[root@localhost ~]# ll -d /testdir
drwxr-x--x 2 root root 4096 Aug 14 07:00 /testdir
[root@localhost ~]# su xiaoming
[xiaoming@localhost root]$ ls /testdir
ls: cannot open directory /testdir: Permission denied

上述实验结果是:用户xiaoming对/tesdir目录无读权限时,利用ls 命令失败

结论是:当某一用户对某目录无读权限时,是无法利用ls 命令查看目录下的文件列表

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

接第一题的操作:

[root@localhost ~]# chmod o-w /testdir
[root@localhost ~]# ll -d /testdir
drwxr-xr-x 2 root root 4096 Aug 14 07:00 /testdir
[root@localhost ~]# su xiaoming
[xiaoming@localhost root]$ cd /testdir
[xiaoming@localhost testdir]$ ls
file1
[xiaoming@localhost testdir]$ touch test
touch: cannot touch `test': Permission denied
[xiaoming@localhost testdir]$ rm -f file1
rm: cannot remove `file1': Permission denied

上述实验结果是:用户xiaoming对/testdir目录无写权限时,利用touch 和rm 命令失败

结论是:当某一用户对某目录无写权限时,是无法在该目录下创建新文件和删除原有文件的

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

[root@localhost ~]# groupadd sysadmins
[root@localhost ~]# cp /etc/fstab /var/tmp
[root@localhost ~]# cd /var/tmp
[root@localhost tmp]# ll
-rw-r--r-- 1 root root 921 Aug 14 07:52 fstab
[root@localhost tmp]# chown xiaoming:sysadmins fstab
[root@localhost tmp]# chmod ug=rw,o= fstab
[root@localhost tmp]# ll fstab
-rw-rw---- 1 xiaoming sysadmins 921 Aug 14 07:52 fstab

5,误删除了用户xiaoming 的家目录,请重建并恢复该用户家目录及相应的权限属性
[root@localhost ~]# cp -r /etc/skel/. /home/xiaoming
[root@localhost ~]# cd /home/xiaoming
[root@localhost xiaoming]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .gnome2  .mozilla
[root@localhost home]# ll -d xiaoming
drwxr-xr-x 4 root root 4096 Aug 14 21:59 xiaoming
[root@localhost home]# chown -R xiaoming:xiaoming xiaoming
[root@localhost home]# ll -d xiaoming
drwxr-xr-x 4 xiaoming xiaoming 4096 Aug 14 21:59 xiaoming
[root@localhost home]# chmod 700 xiaoming
[root@localhost home]# ll -d xiaoming
drwx------ 4 xiaoming xiaoming 4096 Aug 14 21:59 xiaoming

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

  其它用户(不属于g1,g2,g3)不能访问这个文件夹

[root@localhost ~]# mkdir -p /data/testdir
[root@localhost ~]# ls -ld /data/testdir
drwxr-xr-x 2 root root 4096 Aug 14 22:11 /data/testdir
[root@localhost ~]# useradd alice
[root@localhost ~]# useradd tom
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# chgrp g1 /data/testdir
[root@localhost ~]# ls -ld /data/testdir
drwxr-xr-x 2 root g1 4096 Aug 14 22:11 /data/testdir
[root@localhost ~]# chmod g+s /data/testdir
[root@localhost ~]# ls -ld /data/testdir
drwxr-sr-x 2 root g1 4096 Aug 14 22:11 /data/testdir
[root@localhost ~]# gpasswd -g g2 -a alice
Adding user alice to group g2
[root@localhost ~]# gpasswd -g g3 -a tom
Adding user tom to group g3
[root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir
[root@localhost ~]# setfacl -m d:g:g3:r /data/testdir
[root@localhost ~]# 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-x

7,三种权限rwx对文件和目录的不同意义

对于文件

  r:可获取文件的数据

    通常是对文本文件有意义,对二进制文件无意义

  w:可修改文件的数据

    可清空文件的数据,但不能删除文件

  x:可将次文件运行为进程,普通文件没有执行权限,也不应该有权限有执行权限,系统默认的

    执行权限通常只对可执行文件和脚本

对于目录:

  r:可使用ls命令获取目录下的所有文件列表,若想对目录内的文件进行读、写、执行的操作,

    则需看文件的对应权限

  w:可在此目录内创建文件,也可以删除此目录中的文件

  x:可使用ls -l命令查看此目录中的文件的属性,可cd进入此目录

8,umask 和acl mask的区别和联系

  设置了mask后,除所有者其他人以外的用户和组的facl权限都不能大于mask,可以小于或等于

  umask的值是用户默认创建文件和目录的权限,默认的文件权限是666-umask的结果,

  如果相应位有奇数则要+1,目录的权限是777-umask的结果

  相同点:都是限制用户的权限

       umask限制用户新建文件或目录的权限

       mask限制除所有者和其他人以外的权限

  不同点:所限制权限的程度不同

       umask限制用户的权限位精确到其对应的读、写、执行

       mask限制除所有者和其他人以外的用户和组的权限可以小于等于mask,但不能超过mask

9,三种特殊权限的应用场景和作用

 Suid只对二进制程序起作用,程序发起者在程序执行的时候继承程序拥有者的身份以程序拥有者的权限,以程序拥有者的身份去执行程序。

 应用场景为root用户给普通用户分配需要经常改动的配置文件的修改权限比如密码passwd.

 Sgid作用:对二进制程序的作用与Suid基本一致。对目录的作用,当目录设置Sgid时,若用户在此目录下所创建的新文件的用户组与此目录的用户组一致。

 应用场景:在开发的时候需要将开发的东西共享出来大家都可以随时加入新成员不用再设置所属组对共享文件进行查看修改。

     Sticky:目录设置后,所有用户只能对自己创建的文件进行增删改查,无法对其他人的文件进行删除、移动、重命名等操作。


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

  # umask 066 仅对当前shell有效

  更改~/.bash 或 ~/.bash_profile 写入umask 066

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

[root@localhost testdir]# touch f1
[root@localhost testdir]# ll
-rw-r--r-- 1 root root 0 Aug 15 00:04 f1
[root@localhost testdir]# setfacl -m u:user1:0,g:g1:rw f1
[root@localhost testdir]# getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
user:user1:---
group::r--
group:g1:rw-
mask::rw-
other::r--

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

[root@localhost testdir]# mkdir dir
[root@localhost testdir]# setfacl -m d:u:user1:rw,d:g:g1:0 dir
[root@localhost 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


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

[root@localhost testdir]# getfacl -R . > /tmp/acl.txt
[root@localhost testdir]# setfacl -b -R .
[root@localhost testdir]# getfacl -R .
[root@localhost testdir]# setfacl -R --set-file=/tmp/acl.txt .
[root@localhost testdir]# getfacl -R .

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

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

相关推荐

  • 十三.Linux博客-2016年8月18日while、for特殊用法、selet循环与菜单、函数

    格式说明: 操作 概念 命令 说明及举例 十三.while、for特殊用法、selet循环与菜单、函数 while特殊用法 while循环的特殊用法(遍历文件的每一行): while read line; do 循环体 done < /PATH/FROM/SOMEFILE 依次读取/PATH/FROM/…

    Linux干货 2016-08-24
  • redis主/从配置及基于sentinel的故障转移

     一、NoSQL基础概念: ACID:原子性、一致性、隔离性、持久性;特性:数据量大、数据变化非常大(数据增长化、流量分布变化、数据间耦合结构变化)、数据源很多; CAP、BASECAP C:多个数据节点的的数据一致;A:用户发出请求后的有限时间范围内返回结果;P:network partition,网络发生分区后,服务是否依可用;CAP理论:一个分布式系统…

    Linux干货 2017-12-18
  • N21第五周

    1.显示/boot/grub2/grub.cfg中以至少一个空白字符开头的行; ]# grep '^[[:space:]]\+' /boot/grub2/grub.cfg 2.显示/etc/rc.d/init.d/functions文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; ]#…

    Linux干货 2016-08-15
  • 用户及权限管理

    新建用户用到的相关文件/etc/default/useradd /etc/login.defs /etc/skel/* 批量创建用户1.创建用户列表user.txt(文件格式同/etc/passwd) 2.newusers user.txt 3.创建密码文件passwd.txt(格式  用户名:密码) 4.cat passwd.txt | chpa…

    Linux干货 2016-08-11
  • Linux网络属性配置,计算机基础

    Linux网络属性配置,计算机基础 Linux网络属性配置(1): 计算机网络通信:TCP/IP 通过流式化数据相互通信,通过双方一致的时钟频率来完成信号传输; 有两种方式传输:同步传输,异步传输; 借助于介质传输:同轴电缆、网线、无线等; 要想相互通信,也要必须遵循一种(复杂)组织机制,就产生了协议; 通过把协议分层,来分别解决传输过程中各种复杂的操作; …

    Linux干货 2016-09-05
  • N26-第六周博客

    vim编辑器及简单shell脚本示例 请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; [root@localhost tmp]# vim rc.sysinit:%s@^[[:space:]]\+[^[:s…

    系统运维 2017-02-16