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

it2025-06-06  68

关于ntfs权限的问题

文件的权限:

[-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的參数进行设置:

chmod 777 /dir/file 设置文件为读写运行 chmod -x /dir/file 删除文件uga的可运行 chmod ga-w /dir/file 删除文件ga的可写权限 chmod u=rx /dir/file 重设置文件u为读和运行 chmod +x /dir/file 添加文件uga为可运行

umask & fmask & dmask的使用

umask —— 设置文件夹和文件的权限过滤 fmask —— 设置文件的权限过滤 dmask —— 设置文件夹的权限过滤 dmask和fmask是mount的选项。针对fat/ntfs文件系统。适用于fstab配置 不同于chmod/chown的权限值,它们三个是有mask——过滤的意思 。下面是它们的对文件的读写权限: 0 1 2 3 4 5 6 7 r + + + + - - - - w + + - - + + - - x + - + - + - + -

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

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

fstab实例:

<file system> <mount point> <type> <options> <dump> <pass> /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命令改变一个文件的权限: umask 查看当前文件夹的权限mask umask <mask> 设置当前

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

当文件设置了suid后,该文件执行时以拥有者身份执行 chmod 755 file (owner) chmod u+s file ==> -rwsr-xr-x (user) (即当使用user运行时。它以owner的身份运行) (suid经常使用于文件上,文件夹一般没有运行权限)

当文件夹设置了sgid后。其它人要是有r/x/w权限时,其它人创建的子文件夹的组为当前拥有的组

chmod 757 dir (owner) chmod g+s dir ==> drwxr-srwx (ower) mkdir dir/newidr (user) (即当user创建子文件夹时。它的组是owner,它的拥有者则是user) (sgid经常使用于文件夹上)

当文件夹设置了sticky后,防止别人删除文件夹的资料

chmod 757 dir (owner组) chmod o+t dir ==> drwxr-srwt (owner) rm -r dir (user) ==> error (user无法删除。尽管开放了删除权限。但还是仅仅有owner可删除)

样例:

chmod u=rwxs,o=rx file chmod g+s,o=wrx test/ chmod o=rwxt test/ chmod 1775 test/

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

(能够理解为suid=4,sgid=2,sticky=1) suid sgid sticky 模式数字 on on on 7 on on off 6 on off on 5 on off off 4 off on on 3 off on off 2 off off on 1 off off off 0

文件的拥有者

一般通过chown进行设置 查看当前登录 w或者who 查看当前username whoami 查看当前用户组id id <u> 或者 finger <u> 查看用户登录记录 last lastb 查看全部用户 cut -d : -f 1 /etc/passwd cat /etc/passwd |awk -F \: '{print $1}' 查看当前组 groups 查看指定组 groups 改变拥有者 chown /dir/file 改变组 chgrp /dir/file 改变组及拥有者 chown : /dir/file 其它 groupadd/groupmod/groupdel useradd/usermod/userdel

最后进阶理解fstab配置

<file system> <mount point> <type> <options> <dump> <pass> /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

转载于:https://www.cnblogs.com/bhlsheji/p/5327718.html

最新回复(0)