`

Linux文件权限,chmod

 
阅读更多

权限符号意义

符号 代表意义 数字
r

文件:可读

路径:仅能读取路径结构列表

4
w

文件:可写

路径:可新增、删除、移动路径下的文件

2
x

文件:可执行

路径:可进入该路径,访问该路径下的文件

1
s

suid:仅对二进制文件有效,如/usr/bin/passwd

sgid:对文件和路径都有效

使文件有暂时拥有所有者或群组的权限

4

2

 

t sbit:主要对路径有效。只能删除自建的文件,如/tmp/ 1

 

主要语法

chmod [option] mode[,mode]... file...

chmod [option] octal-mode file...

 

mode

改变文件权限可以通过2种模式。符号模式和8进制数字模式。

符号模式 

chmod

u(拥有者)

g(群组)

o(其他)

a(所有)

+(加入)

-(减去)

=(设定)

r(可读)

w(可写)

x(可执行)

s(suid/sgid)

t(sbit)

file

 

8进制数字模式

 

suid/sgid/sbit

拥有者

群组

其他

 
chomod

0-7

0-7

0-7

0-7

file

r=4,w=2,x=1,rwx=7,rw=6,rx=5

suid=4,sgid=2,sbit=1

 

 

用例

1 用2种模式改变文件权限,将此文件变成可执行文件,并且其他人无法修改

$ chmod 755 ~/testfile
$ chmod u=rwx,go=rx ~/testfile

 

2 使文件对于所有用户,添加可写的权限
$ chmod a+w ~/testfile

 

3 用2种模式,给可执行文件加入suid权限
$ chmod 4755 ~/testfile            //testfile原权限为755
$ chomd u+s ~/testfile

 

4用2种模式,给路径加入sgid权限。常用于群组中用户间数据的共享

$ chomd 2755 ~/testpath/           //testpath原权限为755
$ chmod g+s ~/testpath/

 

5 用2种模式,给路径加入sbit权限

$ chmod 1755 ~/testpath            //tsetpath原权限为755
$ chmod o+t ~/testpath

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics