Linux下用户的权限和chmod,chgrp,chown的使用

本文介绍了在Linux环境下如何使用chmod、chgrp和chown命令来管理文件和目录的权限。通过示例展示了如何在不同用户权限下更改文件的读、写、执行权限,以及当遇到权限问题时如何切换到root用户进行操作。同时提到了chgrp用于改变文件所属用户组,而chown用于改变文件所有者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

更改权限

linux下的系统与用户组

在这里插入图片描述

[qiujianru@localhost /]$ cd /usr/local/test/
[qiujianru@localhost test]$ ll test下的目录或文件
总用量 0
-rw-r–r--. 1 root root 0 3月 21 14:35 a.txt
-rw-r–r--. 1 root root 0 3月 21 14:35 b1.txt
-rw-r–r--. 1 root root 0 3月 21 15:08 c.txt
[qiujianru@localhost test]$ chmod u,g,o=rwx a.txt
chmod: 无效模式:“u,g,o=rwx”
Try ‘chmod --help’ for more information.
[qiujianru@localhost test]$ chmod u,g,o=rwx ./a.txt
chmod: 无效模式:“u,g,o=rwx”
Try ‘chmod --help’ for more information.

[qiujianru@localhost test]$ chmod u+rwx,g+rwx,o=rwx a.txt
chmod: 更改"a.txt" 的权限: 不允许的操作

也就是说a.txt对其他组的成员来说没有执行的权限,所以要在root下去更改权限 就看上面的第三列文件的所有者是谁即可

[qiujianru@localhost test]$ chmod o+w a.txt
chmod: 更改"a.txt" 的权限: 不允许的操作
[qiujianru@localhost test]$ su root
密码:
[root@localhost test]# chmod o+w a.txt

因为文件的所有者是root,所以要在root下更改权限

[root@localhost test]# ll
总用量 0
-rw-r–rw-. 1 root root 0 3月 21 14:35 a.txt
权限已更改
-rw-r–r--. 1 root root 0 3月 21 14:35 b1.txt
-rw-r–r--. 1 root root 0 3月 21 15:08 c.txt
[root@localhost test]#

[root@localhost test]# chmod o+w a.txt
[root@localhost test]# ll
总用量 0
-rw-r–rw-. 1 root root 0 3月 21 14:35 a.txt
-rw-r–r--. 1 root root 0 3月 21 14:35 b1.txt
-rw-r–r--. 1 root root 0 3月 21 15:08 c.txt
[root@localhost test]# vi c.txt
Root对c.txt进行了编写
[root@localhost test]# cat c.txt
你一定可以的!!!
[root@localhost test]# su qiu
用户切换到qiu下面,qiu当前要对test目录下的文件进行操作
[qiu@localhost test]$ cat c.txt
你一定可以的!!!
[qiu@localhost test]$ vim c.txt
Qiu 不可以编写c.txt 因为c.txt对其他组的用户没有写的权限,c.txt所有者是root,所以要在root下对test目录下的c.txt进行编写
记住一件很重要的事情:更改权限一定去文件的所有者下去更改

2:chgrp和chown
他俩都是在root权限下去更改的,chgrp是改用户组,chown是改用户名

chown chgrp chmod的详解

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

含笠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值