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 16:09
下一篇 2016-08-08 16:11

相关推荐

  • 无痛之ext3升ext4[原创]

    一台文件存储服务器单目录下子目录已经突破31998数限制,造成无法继续创建子目录,服务器系统环境为CentOS5.4 内核版本为2.6.18。解决方案只能是升级到ext4文件系统,首先到https://ext4.wiki.kernel.org/index.php/Ext4_Howto查了一下资料,文中的第一句便是“Ext4 was released as a…

    Linux干货 2015-03-27
  • find、locate详细解析

    文件查找 在linux系统中如果我们不知道具体的文件的具体位置,我们可以使用文件查找命令来找到我们想找的文件,linux中也有相当优秀的查找命令,(如locate、find),通常查找速度快是locate,因为它是利用数据库查找的,所以速度很快,而find是全磁盘扫描进行查找,所以速度比较慢。 locate和find都是在文件系统上查找符合条件的文件含义。 …

    Linux干货 2016-08-13
  • 十三.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
  • 学习一个星期的沿途体会

    人生处处都是坑,只看跳的深不深。下面就来介绍介绍我跳的坑吧!当然我可没打算在此长眠 既然选择了Liunx,那对它的历史就得了解清楚。就如同我们结婚,既然选择了对方,那就要了解他的过去,包容他的未来。           Linux操作系统是一个叫Linus Torvalds的大学生在1991年开发而来。当然,…

    2017-07-16
  • linux用户组和权限管理

    用户组和权限管理  概念 用户分为三类: 1、超级用户:root uid=0,简单来说uid为0的用户就是超级用户。 2、虚拟用户:存在linux中,满足文件或者程序运行的需要,而创建的。不能登录,不能使用。uid=1-499,1-999(centos7) 3、普通用户:管理员root创建的用户。uid=500+,1000+(centos7) 用户…

    Linux干货 2017-07-29
  • mariadb基础应用

    mariadb基础应用 一、 前言 MariaDB is one of the most popular database servers in the world. It’s made by the original developers of MySQL and guaranteed to stay open source. Notable users …

    Linux干货 2016-12-16