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。
要求该文件必须是可执行文件。

唯有不断学习方能改变! -- Ryan Miao

Linux中读写权限相关推荐

  1. web 上传文件到linux没权限,Javaweb上传文件到Linux 没有读写权限

    一. 问题描述 背景描述: 0.saas-business-运营后台,website-网站页面. 1.javaweb程序(saas-business)部署在linux系统 tomcat服务器下,使用该 ...

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

    简单了解一下linux中的文件权限格式与chmod命令 chmod命令:改变文件或者目录的权限 格式:chmod [参数] [] -R 或者--recursive 递归处理,表示将指定目录下的所有文件 ...

  3. linux中用户的权限是什么,linux中用户权限设置与更改相关介绍(上)

    不管是在生活中还是在工作中,我们都会经常碰到关于电脑权限方面的一些问题.现在介绍一下在linux系统中关于如何设置和管理用户的权限问题,介绍基本但很重要的命令. 在Linux中,权限分为三大类:基本权 ...

  4. java linux 权限管理_权限管理java实现(源于Linux中的权限管理算法)

    这个帖子由来已久吧,我也是到处搜到的,然后仔细学习,果然博大精深,然后加强点弄点自己的东西 我已声明 部分转载!! 向大家介绍一种很不错,也是Linux中的权限管理算法. 定义a^b为:a的b次方 假 ...

  5. linux文件目录含义,Linux中文件权限目录权限的意义及权限对文件目录的意义

    linux中目录与文件权限的意义 一.文件权限的意义 r:可以读这个文件的具体内容: w:可以编辑这个文件的内容,包括增加删除文件的具体内容: x:文件就具有了可执行的权限-------注意:这里和w ...

  6. linux中的acl权限,linux中的权限和ACL

    权限,特殊权限,FACL 用ls -l filename 可以查看文件或者目录的详细信息,具体分析一下 在第一个空格前,有10个字段,第一个"-"表示文件类型,后边"rw ...

  7. linux 0644权限,Linux 中的权限 -- 0755 和 0644

    Linux 系统中采用三位十进制数表示权限,如0755, 0644.windows OS不行.如,对root文件夹abc,进行修改权限(包含其子文件夹)sudo chmod -R 777 abc AB ...

  8. linux中修改权限命令,如何修改权限命令chmod用法

    Linux中的Chmod命令用于更改或分配文件和目录的权限.在Linux/Unix系统中,文件和目录的可访问性是由文件所有权和权限决定的.在本教程中,我们将介绍chmod命令. chmod命令(cha ...

  9. linux中s权限大小写的区别,Linux中的权限

    1.文件与目录权限 1)UID与GID ØUID UID是一个数值,是Linux系统中唯一的用户标识,用于区别不同的用户.在系统内部管理进程和文件保护时使用UID字段.在Linux系统中,注册名和UI ...

最新文章

  1. linux常用特殊符号大全
  2. STM32 UART串口驱动程序
  3. IntelliJ IDEA下载激活
  4. Android中利用HttpClient建立一次持久的连接
  5. 基于2D-RNN的鲁棒行人跟踪
  6. VMware安装VMwaretools
  7. 高并发内存占用持续下降_师兄,为什么删除数据后,Redis内存占用依然很高?...
  8. 线性存储的最短平均检索时间(洛谷P1253题题解,Java语言描述)
  9. 【数据结构与算法】单链表的Java实现
  10. 如何在aspx页面中插入swf动画
  11. MobileNetV2: Inverted Residuals and Linear Bottlenecks
  12. window.onload()方法和window.onscroll()方法
  13. Cell子刊:北大姜长涛组发现HIF-2α通过肠道菌群调控脂肪产热
  14. 谷歌浏览器google80以上版本开发调试跨域问题处理,SameSite设置
  15. URL重定向(跳转)漏洞
  16. keil出现蓝色小箭头
  17. T1118,T1677,T1122
  18. Excel公式大全 excel自动求减 15个常用excel函数公式
  19. 12.匹配一次或多次出现的字符
  20. PTA(每日一题)7-1 jmu-JavaPython-统计一段文字中的单词个数并按单词的字母顺序排序后输出

热门文章

  1. Android 注册登入界面完美设计
  2. 更上层楼:动态安装你的windows服务
  3. Template Method(模板方法)模式
  4. 折腾Java设计模式之责任链模式
  5. flask 常见关系模板代码
  6. 我的人工智能机器人的游戏
  7. 极客Web前端开发资源大荟萃#007
  8. [原] Android中怎么将图片平铺
  9. 关于校验规则(Validation Rule)和业务规则(Bussiness Rule)的思考
  10. [BizTalk]好用的BizTalk管理工具