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. tomcat:域名指向项目名

    把项目部署到tomcat目录webapps后,使用域名访问的时候域名后面需要加上项目名称,如果想直接输入域名就可以访问项目呢?看了下tomcat官方文档,我修改了tomcat安装目录下conf/ser ...

  2. JavaScript资源大全中文版(Awesome最新版--转载自张果老师博客)

    JavaScript资源大全中文版(Awesome最新版)   目录 前端MVC 框架和库 包管理器 加载器 打包工具 测试框架 框架 断言 覆盖率 运行器 QA 工具 基于 Node 的 CMS 框 ...

  3. jquery/zepto 圣诞节雪花飞扬

    下载地址: http://www.html5tricks.com/jquery-html5-christ-snow.html 演示地址: http://www.html5tricks.com/jque ...

  4. 编写一个基本的连接池来实现连接的复用&一些工程细节上的优化

    package it.cast.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQL ...

  5. (翻译)《Hands-on Node.js》—— Why?

    事出有因 为何选择event loop? Event Loop是一种推进无阻塞I/O(网络.文件或跨进程通讯)的软件模式.传统的阻塞编程也是用一样的方式,通过function来调用I/O.但进程会在该 ...

  6. 几种简单的负载均衡算法及其Java代码实现

    什么是负载均衡 负载均衡,英文名称为Load Balance,指由多台服务器以对称的方式组成一个服务器集合,每台服务器都具有等价的地位,都可以单独对外提供服务而无须其他服务器的辅助.通过某种负载分担技 ...

  7. 一个App完成入门篇(七)- 完成发现页面

    第七章是入门篇的倒数第二篇文章了,明天整个APP将进入收官. 本节教程主要要教会大家使用二维码扫描和用do_WebView组件加在html页面. 导入项目 do_WebView组件 扫描功能 自定义事 ...

  8. iOS7的启动画面设置及asset catalogs简介

    如果上网搜索一下“iOS App图标设置”或者“iOS App启动画面设置”肯定能找到不少文章,但内容大多雷同,就是让你按照某种尺寸制作若干张png图片,再按照苹果的命名规范,加入到项目中去,一行代码 ...

  9. ASP.NET MVC 从零开始 - create and run

    这篇文章是从我的 github 博客 http://lxconan.github.io 导入的. 如果你想用 ASP.NET MVC 创建一个网络应用,那么你可以搜到很多的文章.但是没有多少文章告诉你 ...

  10. JS实战 · 表单验证

    思路:         1.定义页面             通过表格格式化表单:             表格行都有自己的背景颜色:             单元格中的数据(文本等)用div进行封装 ...