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,如若转载,请注明出处:https://www.178linux.com/29792

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

相关推荐

  • N25第二周作业

    第二周作业 一、Linux上的文件管理类命令有哪些,其常用的使用方法以及相关实例演示 演示用结构  [root@centos01 yanshi]# tree -a /tmp/yanshi/   /tmp/yanshi/ ├── a │   └── 1…

    Linux干货 2016-12-14
  • N22第三周作业

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

    Linux干货 2016-08-29
  • Linux 系统中screen命令不能使用的解决办法,screen包的正确安装

           有些同学可能在安装完Linux发行版之后,发现screen功能不能实现,这是因为是实现该功能的包在安装系统的过程中没有安装上,这里我根据自己的经验介绍两种安装screen包的方法,用来你实现screen命令。 方法一、     条件:连网状态;   &nb…

    Linux干货 2017-07-12
  • Linux系统的终端类型

    一、什么是Linux终端     终端–用户用户与主机交互,必然要用到的设备。     早期的大型机,想使用的用户很多,但是主机只有一个,也不可能人手一台,但是可以做到在主机上接一个分屏器,分屏器的每一个端子上可以接上一套鼠标键盘显示器,就可以直接在主机上进行一些操作了,这就相当于每个人在独立的操作一台计算…

    Linux干货 2016-10-18
  • Haproxy+keepalivd+LAMP

    目录 一、试验部署 1、实验要求 2、实验准备 3、拓扑结构 4、网络规划 二、基础设置 1、LAMP配置 2、HAProxy配置 3、Keepalived配置 三、测试 四、总结 一、试验部署 1、实验要求 (1) 动静分离部署wordpress,动静都要能实现负载均衡,要注意会话的问题; (2) 给出设计拓扑,写成博客; (3)haproxy的设定要求:…

    Linux干货 2017-05-18
  • Linux运维学习历程-第六天-Linux重定向和管道

    Linux运维学习历程-第六天-Linux重定向和管道 2 本章内容我们将学习linux中的重定向和管道两大用法   I/O输入与输出设备   重定向   管道   tee命令与tr命令 一、I/O设备   1、什么是I/O设备   管理和控制计算机的所有输入/输出(I/O)设备是操作系统…

    Linux干货 2016-08-03