快速学会使用文件的权限

本文详细介绍了在Linux中创建文件、目录,设置文件属主、属组、suid、sgid、sbit,以及如何使用ACL进行权限管理。包括chmod指令的正确使用和chown/chmod/acl命令的操作实例。

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

4创建文件,并赋予权限611(两种方式,一种guoa,一种nnn)

[root@Myliunx ~]# touch file1
[root@Myliunx ~]# ls -l file1
-rw-r--r-- 1 root root 0 Jul 21 20:45 file1
[root@Myliunx ~]# chmod 000 file
[root@Myliunx ~]# chmod u+r,w g+x o+x file
chmod: invalid mode: ‘u+r,w’
Try 'chmod --help' for more information.
[root@Myliunx ~]# chmod u+rw g+x o+x file
chmod: cannot access 'g+x': No such file or directory
chmod: cannot access 'o+x': No such file or directory
[root@Myliunx ~]# chmod u+rw,g+x,o+x file
[root@Myliunx ~]# ll file
-rw---x--x 1 root root 13 Jul 20 10:59 file

5.创建目录,并赋予权限755(两种方式,一种guoa,一种nnn)

[root@Myliunx ~]# mkdir file1
mkdir: cannot create directory ‘file1’: File exists
[root@Myliunx ~]# mkdir file3
[root@Myliunx ~]# chmod 755 file3
[root@Myliunx ~]# ls -l file3
total 0
[root@Myliunx ~]# ls -ld file3
drwxr-xr-x 2 root root 4096 Jul 22 00:02 file3
[root@Myliunx ~]# 

6.创建文件,并将文件的属主和属组修改其他用户

[root@Myliunx ~]# ls /home
user1
[root@Myliunx ~]# chown user:user file
chown: invalid user: ‘user:user’
[root@Myliunx ~]# chown use1r:user1 file
chown: invalid user: ‘use1r:user1’
[root@Myliunx ~]# chown user1:user1 file
[root@Myliunx ~]# ls -l file
-rw---x--x 1 user1 user1 13 Jul 20 10:59 file
[root@Myliunx ~]# 

7.设置suid,为文件设置suid(两种方式 u+s和nnnn)的方式

[root@Myliunx ~]# ls -ld file3
drwxr-xr-x 2 root root 4096 Jul 22 00:02 file3
[root@Myliunx ~]# ll file
-rw---x--x 1 user1 user1 13 Jul 20 10:59 file
[root@Myliunx ~]# chmod 4777 file
[root@Myliunx ~]# ll file
-rwsrwxrwx 1 user1 user1 13 Jul 20 10:59 file

8.设置sgid, 为文件设置sgid(两种方式 g+s和nnnn)的方式

[root@Myliunx ~]# chmod g+s file
[root@Myliunx ~]# ll file
-rwsrwsrwx 1 user1 user1 13 Jul 20 10:59 file

9.设置sbit,为目录设置sbit(两种方式 o+t和nnnn)的方式

[root@Myliunx ~]# ll -d file3
drwxr-xr-x 2 root root 4096 Jul 22 00:02 file3
[root@Myliunx ~]# chmod o+t file3
[root@Myliunx ~]# chmod 1000 file3
[root@Myliunx ~]# ll -d file3
d--------T 2 root root 4096 Jul 22 00:02 file3

10.创建文件,查询文件的acl

[root@Myliunx ~]# getfacl file4
# file: file4
# owner: root
# group: root
user::rw-
group::r--
other::r--

为文件设置acl 用户为testuser1 权限为 rwx
[root@Myliunx ~]# setfacl -m u:testuer:rwx file1
为文件设置acl的mask: 权限为r-x
[root@Myliunx ~]#  setfacl -m m::rx file

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值