learn the auth of Linux.
 
Generally, r-x
w: write , modify and delete  -2
r: read   -4
x: execute  -1
 
A file has 3 auth show:
-owner
-group
-other
 
当时用sudo的时候表示使用root用户的身份,因此,新建的文件或者dir都是root用户的而不是你自己的。这时,自己反而没有权限:
我sudo创建了文件,然后想要修改的时候说没有权限。在脚本中,>输出这个命令就无法执行了。
 
the owner has the 7 with the file, group useually 5, other 5. If I don't want others read the file , just chmod 750, but there is a problem: how can the specific person get the auth?
 
That is I want someone or a specific group get the auth of a file but others can't. Then, the ACL is do this.
 
 
1.Auth to specificer
The following show auth to dir for user:st
 
//create a dir named project
mkdir project
chmod 770 project/
 
//add two uers to tgroup
useradd bimm
useradd cangls
groupadd tgroup
gpasswd -a bimm tgroup
gpasswd -a cangls tgroup
chown root:tgroup project/
 
//auth to user:st
useradd st
setfacl -m u:st:rx project/
//then the ll show +
[root@bogon temp]# ll -d project/
drwxrwx---+ 2 root tgroup 16 5月  14 21:14 project/
 
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
user:st:r-x
group::rwx
mask::rwx
other::---
 
//auth to group:tgroup2
[root@bogon temp]# setfacl -m g:tgroup2:rwx project/  
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
user:st:r-x
group::rwx
group:tgroup2:rwx
mask::rwx
other::---
 
 
2.change mask, the top effective auth
when auth to someone or somegroup by setfacl with a auth like rwx, it will &mask to get their auth.For instance, if
setfacl -m u:st:rw project
, and the project's auth is r-x, then, the auth of user:st to project is r--. Howerver, we can also change the mask:
 
[root@bogon temp]# setfacl -m u:st:rw project/
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
user:st:rw-
group::rwx
group:tgroup2:rwx
mask::rwx
other::---
 
[root@bogon temp]# setfacl -m m:r-x project/
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
user:st:rw-            #effective:r--
group::rwx            #effective:r-x
group:tgroup2:rwx        #effective:r-x
mask::r-x
other::---
 
 
 
3.delete ACL
  -x u:st file(s) , --remove=acl        remove entries from the ACL(s) of file(s)
  -b file(s) , --remove-all                remove all extended ACL entries 
 
[root@bogon temp]# setfacl -x u:st project/
[root@bogon temp]# setfacl -x g:tgroup2 project/
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
group::rwx
mask::rwx
other::---
 
 
4.recursive set ACL and default ACL for dir
if you do it as step2, you just set ACL to the specify dir, not works with the sub-file of the dir.
if you want to do the same with the sub-file, set option -R
 
[root@bogon temp]# touch project/abc
[root@bogon temp]# ll project/abc
-rw-r--r-- 1 root root 0 5月  14 21:14 project/abc
[root@bogon temp]# ll -d project/
drwxrwx--- 2 root tgroup 16 5月  14 21:14 project/
[root@bogon temp]# setfacl -m u:st:rx project/
[root@bogon temp]# ll -d project/
drwxrwx---+ 2 root tgroup 16 5月  14 21:14 project/
[root@bogon temp]# setfacl -m u:st:rx project/
[root@bogon temp]# getfacl project/
# file: project/
# owner: root
# group: tgroup
user::rwx
user:st:r-x
group::rwx
mask::rwx
other::---
 
[root@bogon temp]# getfacl project/abc
# file: project/abc
# owner: root
# group: root
user::rw-
group::r--
other::r--
 
//-R just work with the exists files, but new file doesn't
[root@bogon temp]# setfacl -m u:st:rx -R project/
[root@bogon temp]# getfacl project/abc
# file: project/abc
# owner: root
# group: root
user::rw-
user:st:r-x
group::r--
mask::r-x
other::r--
 
[root@bogon temp]# touch project/newabc
[root@bogon temp]# getfacl project/newabc
# file: project/newabc
# owner: root
# group: root
user::rw-
group::r--
other::r--
 
 
You can see -R dosen't work with new file, if you want the new sub-file also has the auth, use the default ACL by orption d:
 
[root@bogon temp]# setfacl -m d:u:st:rx project/
[root@bogon temp]# getfacl project/newabc
# file: project/newabc
# owner: root
# group: root
user::rw-
group::r--
other::r--
 
[root@bogon temp]# touch project/newabc2
[root@bogon temp]# getfacl project/newabc2
# file: project/newabc2
# owner: root
# group: root
user::rw-
user:st:r-x            #effective:r--
group::rwx            #effective:rw-
mask::rw-
other::---
 
 
-R for the exists and d: for the future.
 
5.setUID
[root@bogon temp]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月  10 2014 /usr/bin/passwd
 
s表示用户在执行时暂时获得文件owner的权限,因为passwd会操作shadow,而只有root才有shadow权限,因此需要在用户运行passwd的时候有权力写入shadow。
要求该文件必须是可执行文件。
 
 
 
 
 
 
 
 
 
 
 

Linux中读写权限的更多相关文章

  1. <实训|第十三天>linux中ACL权限控制以及磁盘配额,附编译属于自己的linux内核

    [root@localhost~]#序言 首先讲讲昨天关于缩容失败,开不机的解决方法:ACL权限也算是一个很重要的知识点,不难,但是很实用:磁盘配额一般不需要自己弄,但是要懂得原理.剩下的就是编译属于 ...

  2. <实训|第九天>掌握linux中普通的权限控制和三种特殊的权限(sst),做合格的运维工程师

    linux中,权限的学习是必不可少的,不论是作为一名运维工程师或者是单一的管理者,学习好linux中的权限控制,你就可以保护好自己的隐私同时规划好你所管理的一切. 权限的学习是很多的,不要认为自己已经 ...

  3. [转]Linux中文件权限目录权限的意义及权限对文件目录的意义

    转自:http://www.jb51.net/article/77458.htm linux中目录与文件权限的意义 一.文件权限的意义 r:可以读这个文件的具体内容: w:可以编辑这个文件的内容,包括 ...

  4. linux中的权限

    第1章 显示或设置网络相关信息 1.1 ip address 与ifconfig 类似 [root@znix ~]# ip address 1: lo: <LOOPBACK,UP,LOWER_U ...

  5. linux 中 修改权限的命令 chmod

    今天被这个命令给黄了, 连这个都记不住,是该好好的复习复习了,问了一个问题,就是说这个tomcat 如何去修改关于这个权限的问题:一下子把我弄蒙了,不说了,心累: 修改linux文件权限命令:chmo ...

  6. linux 中更改权限命令chown,chmod,chgrp

    写在前面,关于chown,chmod的区别 chown用法 用来更改某个目录或文件的用户名和用户组的 chown 用户名:组名 文件路径(可以是就对路径也可以是相对路径) 例1:chown root: ...

  7. linux中文件权限格式与chmod命令以及用户和用户组的管理

    简单了解一下linux中的文件权限格式与chmod命令 chmod命令:改变文件或者目录的权限 格式:chmod [参数] [<权限范围><符号><权限代码>] - ...

  8. win7的目录和vbox的共享,linux中没有权限打开

    来自于 http://www.cnblogs.com/usegear/p/5120427.html win7的目录由vbox共享是个老话题.稳拿网上很多介绍. 在linux中通过文件夹不能打开,说没有 ...

  9. linux中关于权限的一些事

    权限这个东西对于初学者来说可能会有点陌生,不过不要紧,看完下面的讲解应该会对你有一定的帮助 权限rwx rwxrwxrwx  u     g    o         a r:可读      4 w: ...

随机推荐

  1. 【转】WriteMessage的信息在AutoCAD中命令行中实时显示

    之前程序中有段发送信息到命令行上显示的代码,如下:     ed.WriteMessage("开始标注横断面高程,请稍候!");     但是发现命令行中并不马上显示,代码也明明运 ...

  2. ie8 jquery parents() 获取多个的问题

    今天开发的时候碰到了一个奇怪的问题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3 ...

  3. .NET面试题系列[9] - IEnumerable

    .NET面试题系列目录 什么是IEnumerable? IEnumerable及IEnumerable的泛型版本IEnumerable<T>是一个接口,它只含有一个方法GetEnumera ...

  4. 日志系统实战(三)-分布式跟踪的Net实现

    介绍 在大型系统开发调试中,跨系统之间联调开始变得不好使了.莫名其妙一个错误爆出来了,日志虽然有记录,但到底是哪里出问题了呢? 是Ios端参数传的不对?还是A系统或B系统提供的接口导致?相信有不少人遇 ...

  5. iOS-几大框架的介绍

    1.Objective-C之Foundation框架 概述 我们前面的章节中就一直新建Cocoa Class,那么Cocoa到底是什么,它和我们前面以及后面要讲的内容到底有什么关系呢?Objectiv ...

  6. iOS 之APP上架

    前几天在忙着上线,尽管之前已经上线过一次,但由于本身比较菜,还是状况百出. 好在今天终于成功提交,因此来写写心得. 如果是第一次上线,推荐这篇文章: http://jingyan.baidu.com/ ...

  7. SSIS 数据源组件的External Metadata和Advanced Property

    1,SSIS的组件属性ValidateExternalMetadata 如果一个Destination组件使用的是上游创建的staging table,那么必须设置 ValidateExternalM ...

  8. VS-默认端口导致项目不能加载的解决方案

  9. 关于HTML5 Audio线程问题

    移动端果然很坑! 在移动端IOS平台上用new Audio每次调用这个API都会创建一个新的线程,而且还不能销毁...直到拖死应用 后来改进了换了AudioContext,线程问题解决了 https: ...

  10. jQuery 2.0.3 源码分析Sizzle引擎 - 解析原理

    声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 先来回答博友的提问: 如何解析 div > p + div.aaron input[type="checkb ...