lemooljiang avatar

linux文件权限梳理 / 网络研习社#86

lemooljiang

Published: 10 Oct 2023 › Updated: 10 Oct 2023

linux文件权限梳理 / 网络研习社#86

linux的文件权限颇为复杂,简单地读下资料是很难弄明白的,非得实践多次才能完全整明白。以前我是对权限不太重视,不管在哪,都是一个root通行天下。现在有多人协作,以及安全性方面的考虑,需要适当地避免root而使用普通用户的角色。

文件权限是个系统工程,对于linux来说“一切皆文件”。,要梳理这方面的知识,也确实花了近两天的时间。整理和测试后,归纳如下:

doc.png

ll   
ll -d /home/test test

drwxr-xr-x  4 root   root   4096 May 31 09:52 test/
drwxr-xr-x  2 lemool lemool 4096 Sep 28 02:31 lemool/
drwxr-xr-x  2 root   root   4096 Apr  6 13:27 mongodb/
-rw-r--r--  1 root   root     68 Aug 28 07:01 ser.txt

2-4  5-7 8-10 

:
r 4 
w 2 
x 1 
- 0

: 
chmod  + - =  u g o a
chmod [ u / g / o / a ] [ + / - / = ] [ r / w / x ] file
[ u / g / o / a ]  
uUser 
gGroup 
oOther 
aAll
+ 
- 
=
eg:
  chmod u=rwx a.txt  //对a.txt的属主增加所有权限
  chmod u+w a.txt   //对a.txt的属主增加写权限
  chmod u=- a.txt   //对a.txt的属主减去所有权限
  chmod o+w /home/test //对目录test增加其他人的可写权限
  chmod u+rw /code/readme.txt //给User用户增加了对”/code/readme.txt”文件 “w” 和 “x” 的权限
  chown lem.lem test.txt //更改test.txt的属主和属组为lem

  chmod +x 
  chmod +x start.sh

# 也可以数字的形式来代表权限
# r-4 w-2 x-1 --0 几个数字相加得到权限,比如7就是所有权限
chmod o+w /home/test //增加其他人对test文件夹的权限,其他人就可以在此自由的操作了
chmod -R 774 /code/ //修改这个目录,以及子目录下文件的所有权限, -R表示递归
User : 7 = 111   r , w , x  
Group : 7 = 111   r , w , x  
Other : 4 = 100   r   w,x 

总结下来看似简单,但要理解每个符号的意义却要花不少时间和心思。行动起来吧!

Leave linux文件权限梳理 / 网络研习社#86 to:

Written by

Designer , Poet , Technology enthusiasts

Read more #cn posts


Best Posts From lemooljiang

We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From lemooljiang