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)
pingskypingsky
上一篇 2016-08-08
下一篇 2016-08-08

相关推荐

  • Keepalived实现nginx双主

    一、架构描述与应用 1. 应用场景 大多数的互联网公司都会利用nginx的7层反向代理功能来实现后端web server的负载均衡和动静分离。这样做的好处是当单台后端server出现性能瓶颈时可以对其进行横向扩展从而提高整个系统的并发,同时也可以通过后端server提供的http或tcp监控接口对其进行健康检查实现自动Failover和Failback。&n…

    Linux干货 2016-07-16
  • N25期—第二周作业

    1、  Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。   一、文件权限管理类命令  chown:改变文件所有者  chown [OPTION]… [OWNER][:[GROUP]] FILE…  常用参数 -R:递归修改(改目录就改目录中的目录及文件) &n…

    Linux干货 2016-12-11
  • iptables练习

    iptables练习 一、COMMAND 1、列出所有链的规则:iptables -L ,显示某条链的规则就是iptables -L INPUT 详细信息:iptables -vnL 2、清楚所有链的规则 :iptables -F 3、设置默认规则策略:iptables -P INPUT DROP,iptables -P OUTPUT DROP , ipta…

    Linux干货 2016-12-20
  • Shell脚本编程 流程控制—循环

    循环:重复执行所指定的代码片段,直到循环条件不满足,则退出循环 一、for循环     语法格式:     for 变量名 in 列表     do         循环体     done &nbs…

    Linux干货 2016-08-24
  • web服务介绍(三)

    状态码分类:1xx:100-101  额外信息提示2xx:200-206  表示成功类响应3xx:300-305  重定向4xx:400-415  错误类响应码,由于客户端发送错误,如客户端请求一个根本不存在的资源5xx:500-505  错误类信息,服务器端错误,服务器本身一些问题导致请求无法成功 常用状态…

    Linux干货 2017-04-22
  • 开机启动流程

    grub and boot Centos5,6的开机启动流程 grub Centos7的开机启动流程 Centos5,6的开机启动流程 initrd / initramfs 一般存储在/boot目录下,以.img为结尾的文件,是一个小型的根目录系统的映像文件,里面存放了各类系统必须的模组,为了解决内核在加载完成之后没有模组无法访问磁盘加载rootfs的问题。…

    Linux干货 2016-04-11