Linux权限:
安全模型:
文件权限:
r:读权限
w:写权限
x:执行权限
目录权限
r:可以查看目录内内容
w:可以在目录内创建和删除文件
x:可以进入目录 可以用ls -l查看他属性等的权限
rwx:
rw-:有读写没有执行权限
r--:只有读权限
r-w:有读有执行没有写权限 等等
在文件权限上如果对应位有权限那么就是1没有权限就是0
--- | --x | -w- | -wx | r-- | r-x | rw- | rwx | |
二进制 | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
八进制 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
改变文件权限的命令:
chmod:改变文件权限
操作三类用户的权限:使用8进制
chmod [-R] OCTAL -MODE filename...
注:chmod 6 /tmp/testfile这个命令实际全写是chmod 006 /tmp/tetsfile,也就是说chmod会自动补0
操作指定类别使用者的权限:
u:属主
g:属组
o:其他
a:all
指定一个或多个类别=mod (这地方就要写成rwx这样的格式了)
chmod u=w /tmp/testfile 这地方的理解是只改属主的权限,其他用户的权限是不动的,不像上面会自动补0那样
操作指定类别的使用者指定权限位: +/-
chmod u+x /tmp/testfile
--reference=FILE:参考FILE的权限做设定
chmod --reference=filename changefilename
标识参考filename的权限来修改changefilename,执行后changefilename文件的权限就是filename的权限
-R:递归修改
chown:改变属主
chown [-R] [--reference=] USER FILE...
chown [-R] [--reference=] GROUP FILE
chown [-R] [--reference=] USER:GROUP FILE...
chown [-R] [--reference=] USER.GROUP FILE...
chgrp:改变属组
umask是chmod配套的,总共为4位(gid/uid,属主,组权,其它用户的权限),不过通常用到的是后3个,例如你用chmod 755 file(此时这文件的权限是属主读(4)+写(2)+执行(1),同组的和其它用户有读写权限)
默认情况下的umask值是022(可以用umask命令查看),此时你建立的文件默认权限是644(6-0,6-2,6-2),建立的目录的默认 权限是755(7-0,7-2,7-2),可以用ls -l验证一下哦 现在应该知道umask的用途了吧,它是为了控制默认权限,不要使默认的文件和目录具有全权而设的
下面开始图文演示
[[email protected] /tmp/quanxian]$ chmod 000 testfile && ls -l 总用量 0 ---------- 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod +r testfile && ls -l 总用量 0 -r--r--r-- 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod +x testfile && ls -l 总用量 0 -r-xr-xr-x 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod +w testfile && ls -l 总用量 0 -rwxr-xr-x 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$
[[email protected] /tmp/quanxian]$ chmod 777 testfile && ls -l 总用量 0 -rwxrwxrwx 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod -w testfile || ls -l testfile chmod: testfile:新的权限为r-xrwxrwx,而非r-xr-xr-x -r-xrwxrwx 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod -r testfile && ls -l testfile ---x-wx-wx 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod -x testfile && ls -l testfile -----w--w- 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$
[[email protected] /tmp/quanxian]$ ls -l /etc/fstab -rw-r--r--. 1 root root 863 5月 24 05:24 /etc/fstab [[email protected] /tmp/quanxian]$ ls -l testfile -----w--w- 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$ chmod --reference=/etc/fstab testfile [[email protected] /tmp/quanxian]$ ls -l testfile -rw-r--r-- 1 root root 0 5月 24 23:31 testfile [[email protected] /tmp/quanxian]$
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏