[root@python3 ~]#
[root@python3 ~]# vim /etc/passwd
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# vim /etc/group
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root root 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# man chgrp
[root@python3 ~]# man chown
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chgrp -R haha c
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root haha 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chown -R haha c
[root@python3 ~]#
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 haha haha 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chown -R .root c
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 haha root 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chown -R root:haha c
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root haha 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chgrp -R root c
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root root 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
上面是改变用户组和用户的操作
修改文件权限:两种方法,第一种以数字来修改,第二种以符号来修改。
修改权限的语法:chmod
[root@python3 ~]# man chmod
[root@python3 ~]#
[root@python3 ~]# info chmod
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod --help
用法:chmod [选项]... 模式[,模式]... 文件...
或:chmod [选项]... 八进制模式 文件...
或:chmod [选项]... --reference=参考文件 文件...
将每个文件的模式更改为指定值。
-c, --changes 类似 --verbose,但只在有更改时才显示结果
--no-preserve-root 不特殊对待根目录(默认)
--preserve-root 禁止对根目录进行递归操作
-f, --silent, --quiet 去除大部份的错误信息
-v, --verbose 为处理的所有文件显示诊断信息
--reference=参考文件 使用指定参考文件的模式,而非自行指定权限模式
-R, --recursive 以递归方式更改所有的文件及子目录
--help 显示此帮助信息并退出
--version 显示版本信息并退出
每种 MODE 都应属于这类形式"[ugoa]*([-+=]([rwxXst]*|[ugo]))+"。
请向bug-coreutils@gnu.org 报告chmod 的错误
GNU coreutils 项目主页:<http://www.gnu.org/software/coreutils/>
GNU 软件一般性帮助:<http://www.gnu.org/gethelp/>
请向<http://translationproject.org/team/zh_CN.html> 报告chmod 的翻译错误
要获取完整文档,请运行:info coreutils 'chmod invocation'
[root@python3 ~]#
修改权限
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root root 4096 1月 12 10:20 c
-rw-r--r--. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod 777 install_bak.log
[root@python3 ~]# ll
总用量 164
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root root 4096 1月 12 10:20 c
-rwxrwxrwx. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]# ll install*
-rwxrwxrwx. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
[root@python3 ~]#
再次修改权限
[root@python3 ~]# ll install*
-rwxrwxrwx. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
[root@python3 ~]# chmod 630 install_bak.log
[root@python3 ~]# ll install*
-rw--wx---. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
[root@python3 ~]#
上面是以数字类型修改的是文件权限
下面以符合的类型来修改权限
u g o
rwx
±=
用以上字符来进行组合。
[root@python3 ~]# ll hello.txt
-rw-r--r--. 1 root root 391 1月 12 11:21 hello.txt
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod u=rwx,go=rx hello.txt
[root@python3 ~]# ll
总用量 172
drwxr-xr-x. 3 root root 4096 1月 10 09:16 a
-rw-------. 1 root root 1416 11月 22 2022 anaconda-ks.cfg
-rw-r--r--. 1 root root 391 1月 11 18:16 a.txt
drwxr-xr-x. 2 root root 4096 1月 12 08:43 b
drwxr-xr-x. 2 root root 4096 1月 12 10:20 c
drwxr-xr-x. 2 root root 4096 1月 12 11:20 hahaxiix.txt
-rwxr-xr-x. 1 root root 391 1月 12 11:21 hello.txt
-rw--wx---. 1 root root 46478 1月 12 10:22 install_bak.log
-rw-r--r--. 1 root root 46478 11月 22 2022 install.log
-rw-r--r--. 1 root root 10033 11月 22 2022 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 22 2022 公共的
drwxr-xr-x. 2 root root 4096 11月 22 2022 模板
drwxr-xr-x. 2 root root 4096 11月 22 2022 视频
drwxr-xr-x. 2 root root 4096 11月 22 2022 图片
drwxr-xr-x. 2 root root 4096 11月 22 2022 文档
drwxr-xr-x. 2 root root 4096 11月 22 2022 下载
drwxr-xr-x. 2 root root 4096 11月 22 2022 音乐
drwxr-xr-x. 2 root root 4096 11月 22 2022 桌面
[root@python3 ~]# ll hello.txt
-rwxr-xr-x. 1 root root 391 1月 12 11:21 hello.txt
[root@python3 ~]#
[root@python3 ~]#
a是所有人,可以操作所有的权限
root@python3 ~]#
[root@python3 ~]# cp a.txt yy.txt
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# ll yy.txt
-rw-r--r--. 1 root root 391 1月 12 13:24 yy.txt
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod 000 yy.txt
[root@python3 ~]# ll yy.txt
----------. 1 root root 391 1月 12 13:24 yy.txt
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod a+w yy.txt
[root@python3 ~]# ll yy.txt
--w--w--w-. 1 root root 391 1月 12 13:24 yy.txt
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]#
[root@python3 ~]# chmod 777 yy.txt
[root@python3 ~]#
[root@python3 ~]# ll yy.txt
-rwxrwxrwx. 1 root root 391 1月 12 13:24 yy.txt
[root@python3 ~]# chmod a-x yy.txt
[root@python3 ~]#
[root@python3 ~]# ll yy.txt
-rw-rw-rw-. 1 root root 391 1月 12 13:24 yy.txt
[root@python3 ~]#