chmod 赋权所有_Linux下chmod赋权详解

本文详细介绍了Linux文件的rwx权限管理,包括文件的默认权限、umask设置、以及如何使用chmod命令来添加、删除文件或目录的权限。通过实例展示了不同权限设置的效果,如u+x、o-x等,强调了在生产环境中谨慎赋予所有用户执行权限的重要性。
摘要由CSDN通过智能技术生成

Linux文件有rwx即读、写、执行三种权限

管理文件权限

文件访问权限:rwxrwxrwx (777)

权限数值化后:(7)(7)(7)

r   读     -4     允许用户打开、浏览文件内容

w   写     -2     允许用户打开、编辑文件

x   执行   -1     允许用户执行

新创建文件默认权限为rw-r--r-- (644)

默认文件权限根据umask值设置(默认为022)

新文件权限为rw-r-r(644)

666 – 022 = rw-r--r--

新创建目录默认权限为rwxr-xr-x (755)

默认目录权限根据umask值设置(默认为022)

新目录权限为rwxr-xr-x

777 - 022 = rwxr-xr-x

umask

修改权限:chmod

添加、删除文件或目录状态

chmod u+x

chmod u=rwx,g=rw,o=r chmod 764

chmod o-r hello.txt

chmod a+x test     给所有用户other赋予执行权限(生产服务器不推荐给所有用户都赋予执行权限)

chmod u+x test     给当前用户other赋予执行权限

chmod g+x test     给同组用户other赋予执行权限

chmod o+x test     给其他用户other赋予执行权限

chmod +x test      默认是给所有用户赋予执行权限

chmod -x test      默认是给所有用户取消执行权限

去掉相应权限用-,例如:

chmod a-x test     给所有用户other去除执行权限

指定权限用=,例如:

chmod u=rwx test   指定当前用户拥有读写执行权限

实例:

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

[root@RHEL7x64 ~]# touch test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod u+x test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r--. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod o+x test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod g+x test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod a-x test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod a+x test

[root@RHEL7x64 ~]# ll

总用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]#

[root@RHEL7x64 ~]# ll

总用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod +x memtop.sh

[root@RHEL7x64 ~]# ll

总用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod -x memtop.sh

[root@RHEL7x64 ~]# ll

总用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]# chmod u+x memtop.sh

[root@RHEL7x64 ~]# ll

总用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@RHEL7x64 ~]#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值