linux权限及ntfs文件系统权限的知识

http://blog.csdn.net/aegoose/article/details/25439649

关于ntfs权限的问题


文件的权限:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [-dcbps][u:rwx][g:rwx][a:rwx]   
其中: r=4, w=2, x=1,  u=owner, g=group, a=all user
           d=dir, -=file, l=symbolic link, p=pipe, 

           c=character device, b=block device,  d=door, s = socket

linux下,目录的r——可列目录,w——可写/删/改名,x——可进入访问;

                     文件r——可读,w——可写/删/改名,x——执行

权限的组合可汇合成一个数字: rwx = 4+2+1 = 7

因此:-rwxrwxrwx = 777, -rw-rw-rw=666, -rwx-r-x-r-x=755

一般通过chmod的参数进行设置:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. chmod 777 /dir/file 设置文件为读写执行  
  2. chmod -x /dir/file 删除文件uga的可执行  
  3. chmod ga-w /dir/file 删除文件ga的可写权限  
  4. chmod u=rx /dir/file 重设置文件u为读和执行  
  5. chmod +x /dir/file 增加文件uga为可执行  


umask & fmask & dmask的使用

umask —— 设置目录和文件的权限过滤
fmask —— 设置文件的权限过滤
dmask —— 设置目录的权限过滤
dmask和fmask是mount的选项,针对fat/ntfs文件系统,适用于fstab配置
不同于chmod/chown的权限值,它们三个是有mask——过滤的意思 ,以下是它们的对文件的读写权限:
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.     0   1   2   3   4   5   6   7  
  2. r   +   +   +   +   -   -   -   -  
  3. w   +   +   -   -   +   +   -   -  
  4. x   +   -   +   -   +   -   +   -  

其实这个结果是通过 mask = rwx - 文件权限

如设置文件为0755权限,那么mask值则需为0022,即:0755=0777-0022

fstab实例

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <file system> <mount point> <type>         <options>       <dump> <pass>  
  2. /dev/hda1      /media/win    ntfs  defaults,utf8,umask=111   0      0  

其中:umask=111==>(777-111)=666=rw-rw-rw, 即文件拥有读写权限

可以重新设计更更严格的权限关系:

           dmask=022,fmask=133 即:f=755=rwxr-xr-x, d=644=rw-r--r--

注意:其实umask可理解为关闭某些权限。可以使用umask命令改变一个文件的权限:
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. umask 查看当前目录的权限mask  
  2. umask <mask> 设置当前  


文件权限进阶—— 文件的组和用户继承关系suid和sgid

当文件设置了suid后,该文件运行时以拥有者身份执行
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. chmod 755 file (owner)  
  2. chmod u+s file ==> -rwsr-xr-x (user)  
  3. (即当使用user执行时,它以owner的身份执行)  
  4. (suid常用于文件上,目录一般没有执行权限)  

当目录设置了sgid后,其他人要是有r/x/w权限时,其他人创建的子目录的组为当前拥有的组

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. chmod 757 dir (owner)  
  2. chmod g+s dir ==> drwxr-srwx (ower)  
  3. mkdir dir/newidr (user)  
  4. (即当user创建子目录时,它的组是owner,它的拥有者则是user)  
  5. (sgid常用于目录上)  

当目录设置了sticky后,防止别人删除目录的资料

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. chmod 757 dir (owner组)  
  2. chmod o+t dir ==> drwxr-srwt (owner)  
  3. rm -r dir (user) ==> error  
  4. (user无法删除,虽然开放了删除权限,但还是只有owner可删除)  

例子:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. chmod  u=rwxs,o=rx   file  
  2. chmod  g+s,o=wrx    test/  
  3. chmod  o=rwxt   test/   
  4. chmod 1775 test/  

0755也就是755, 而1755前面的1则与suid/sgid/sticky相关,看下表:

(可以理解为suid=4,sgid=2,sticky=1)
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. suid    sgid    sticky  模式数字  
  2. on  on  on  7  
  3. on  on  off 6  
  4. on  off on  5  
  5. on  off off 4  
  6. off on  on  3  
  7. off on  off 2  
  8. off off on  1  
  9. off off off 0  


文件的拥有者

一般通过chown进行设置
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 查看当前登录  w或者who  
  2. 查看当前用户名     whoami  
  3. 查看当前用户组id  id <u>  或者 finger <u>  
  4. 查看用户登录记录  last  
  5.         lastb  
  6. 查看所有用户  cut -d : -f 1 /etc/passwd  
  7.         cat /etc/passwd |awk -F \: '{print $1}'  
  8. 查看当前组       groups  
  9. 查看指定组       groups   
  10. 改变拥有者       chown  /dir/file  
  11. 改变组     chgrp  /dir/file  
  12. 改变组及拥有者 chown : /dir/file  
  13. 其他      groupadd/groupmod/groupdel  
  14.         useradd/usermod/userdel  


最后进阶理解fstab配置

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <file system> <mount point> <type>                    <options>               <dump> <pass>  
  2. /dev/hda1 /media/win ntfs defaults,utf8,uid=1000,gid=1000,fmask=133,dmask=022 0 0  

参考文章

http://www.itlearner.com/article/4594

http://askubuntu.com/questions/429848/dmask-and-fmask-mount-options

http://blog.sina.com.cn/s/blog_70545bad0100xdnp.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值