Linux中读写权限

简介: 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用户的而不是你自己的。
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
目录
相关文章
|
8月前
|
安全 Linux 数据安全/隐私保护
Linux权限详解
Linux权限详解
|
2月前
|
Linux 数据安全/隐私保护
linux特殊权限!!
本文介绍了Linux系统中的特殊权限,包括suid、sgid和sbit。suid使普通用户在执行特定命令时获得root权限;sgid使用户在创建文件时继承目录的用户组权限;sbit确保用户只能删除自己在共享目录中创建的文件。此外,文章还讲解了chattr和lsattr命令,用于更改和查看文件的扩展属性,以及umask的概念和计算方法,帮助理解文件和目录的默认权限。
61 1
linux特殊权限!!
|
3月前
|
运维 监控 安全
Linux_权限理解(详细PLUS)
【10月更文挑战第3天】本文介绍了Linux系统中的权限管理基础,包括文件系统对象与权限关联、权限的继承性、字符与数字表示法的解读,以及用户、组与权限的动态交互。详细解析了`chmod`命令的高级用法和权限修改的风险,探讨了SUID、SGID和Sticky Bit等特殊权限的作用机制,并提出了基于角色的权限分配和定期权限审计的最佳实践。
90 11
|
3月前
|
Linux 数据安全/隐私保护 Windows
Linux_权限理解(详细PLUS
Linux_权限理解(详细PLUS
|
8月前
|
Linux 数据安全/隐私保护
Linux 读写权限的配置
Linux 读写权限的配置
126 0
|
Linux
Linux权限(二)
Linux权限(二)
89 0
|
Linux
Linux的权限
Linux的权限
80 0
|
Linux
Linux基本权限(2)
Linux基本权限(2)
|
Linux Shell Go
Linux权限理解
Linux权限理解
145 0