组管理和权限管理
组管理和权限管理
用户和文件的组概念
Linux每个用户都必须属于一个组,就像每个人都有自己的国家一样。
Linux每个文件都有所有者、所在组、其他组这三个概念。
修改权限一般要
root
权限。
文件和目录的所有者
chown -R
:change owner,修改所有者。-R表示递归修改。[root@Tyc home]# ls -ahl total 16K drwxr-xr-x. 3 root root 4.0K Feb 22 18:46 . dr-xr-xr-x. 18 root root 4.0K Feb 19 20:40 .. -rw-r--r-- 1 root root 0 Feb 22 18:46 apple.txt -rw-r--r-- 1 root root 0 Feb 21 12:28 cat.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 pig.txt -rw-r--r-- 1 root root 48 Feb 21 19:11 test.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 tiger.txt drwx------ 2 tom tom 4.0K Feb 21 14:35 tom [root@Tyc home]# chown tom apple.txt [root@Tyc home]# ls -ahl total 16K drwxr-xr-x. 3 root root 4.0K Feb 22 18:46 . dr-xr-xr-x. 18 root root 4.0K Feb 19 20:40 .. -rw-r--r-- 1 tom root 0 Feb 22 18:46 apple.txt -rw-r--r-- 1 root root 0 Feb 21 12:28 cat.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 pig.txt -rw-r--r-- 1 root root 48 Feb 21 19:11 test.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 tiger.txt drwx------ 2 tom tom 4.0K Feb 21 14:35 tom [root@Tyc home]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
组的创建
groupadd master # 创建一个组master useradd -g master fox #创建一个用户放到master组下面
1
2
文件和目录的所在组
chgrp -R
:change group,修改所在组。-R表示递归修改。[root@Tyc tom]# ls -ahl total 24K drwx------ 2 tom tom 4.0K Feb 22 19:00 . drwxr-xr-x. 3 root root 4.0K Feb 22 18:46 .. -rw------- 1 tom tom 123 Feb 22 19:00 .bash_history -rw-r--r-- 1 tom tom 18 Apr 1 2020 .bash_logout -rw-r--r-- 1 tom tom 193 Apr 1 2020 .bash_profile -rw-r--r-- 1 tom tom 231 Apr 1 2020 .bashrc -rw-rw-r-- 1 tom tom 0 Feb 22 18:55 tom1.txt [root@Tyc tom]# chgrp master tom1.txt [root@Tyc tom]# ls -ahl total 24K drwx------ 2 tom tom 4.0K Feb 22 19:00 . drwxr-xr-x. 3 root root 4.0K Feb 22 18:46 .. -rw------- 1 tom tom 123 Feb 22 19:00 .bash_history -rw-r--r-- 1 tom tom 18 Apr 1 2020 .bash_logout -rw-r--r-- 1 tom tom 193 Apr 1 2020 .bash_profile -rw-r--r-- 1 tom tom 231 Apr 1 2020 .bashrc -rw-rw-r-- 1 tom master 0 Feb 22 18:55 tom1.txt [root@Tyc tom]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
其他组
[root@Tyc tom]# usermod -g wudang tom [root@Tyc tom]# id tom uid=1000(tom) gid=1001(wudang) groups=1001(wudang) [root@Tyc tom]#
1
2
3
4
权限的基本介绍
使用
ls -l
得出的信息,开头10个字符表示文件权限- 第0位确定文件类型(
d,-,l,c,b
)d
表示目录;-
表示普通文件;c
表示字符设备文件,如鼠标、键盘等;b
表示块设备,比如硬盘等,blog。
- 第1-3位确定所有者所拥有的权限;
rwx
三种权限,对于文件和目录的作用分别不用。
- 第4-6位确定所在组的权限;
- 第7-9位确定其他用户所拥有的权限。
- 第0位确定文件类型(
可删除文件的前提要对文件所在目录有
w
权限,同时对文件有w
权限。示例
修改权限
chmod
:修改文件或目录的文件。也可以通过数字更改权限,1-7 包含的所有的组合方式。
上次更新: 2025/06/25, 11:25:50