假冒建设厅网站如何建设cpa影视网站
2026/1/23 20:36:31 网站建设 项目流程
假冒建设厅网站,如何建设cpa影视网站,常用的seo网站优化排名,做钓鱼网站软件一. 先理清#xff1a;Linux 权限的核心逻辑Linux 作为多用户操作系统#xff0c;通过“谁能操作”和“能做什么操作”两大维度控制文件访问#xff0c;核心是 “按角色(身份)分配权限”1.1 两类用户(人)#xff1a;超级用户与普通用户Linux 中用户分为两种#xff0c;权限…一. 先理清Linux 权限的核心逻辑Linux 作为多用户操作系统通过“谁能操作”和“能做什么操作”两大维度控制文件访问核心是 “按角色(身份)分配权限”1.1 两类用户(人)超级用户与普通用户Linux 中用户分为两种权限差异极大超级用户root命令提示符为#可执行系统中任何操作如删除系统文件、修改权限不受限制普通用户命令提示符为$仅能操作自己权限范围内的文件如修改自己的文档受严格限制。代码语言javascriptAI代码解释[rootVM-4-4-centos lesson5]# adduser yhr [rootVM-4-4-centos lesson5]# passwd yhr Changing password for user yhr. New password: Retype new password: passwd: all authentication tokens updated successfully.通过su****su-命令可切换用户示例su只进行“身份切换”不改变当前的工作环境环境变量、工作目录等。su -进行“完整的登录切换”会模拟一次完整的登录过程包括切换工作目录和加载目标用户的环境变量代码语言javascriptAI代码解释# 普通用户whb切换到root需输入root密码 [whbbite-alicloud ~]$ su root Password: [rootbite-alicloud ~]# whoami # 验证当前用户 root # root切换到普通用户whb无需密码 [rootbite-alicloud ~]# su whb [whbbite-alicloud ~]$ whoami whb #su [zhangsanserver ~]$ pwd /home/zhangsan [zhangsanserver ~]$ su Password: # 输入root密码 [rootserver zhangsan]# pwd # 注意提示符显示还在zhangsan的目录 /home/zhangsan #su- [zhangsanserver ~]$ pwd /home/zhangsan [zhangsanserver ~]$ su - Password: # 输入root密码 [rootserver ~]# pwd # 已经切换到root的家目录 /root当然还有个指令是sudo这个是不用切换用户短暂的对普通用户进行提权但是前提是该用户在白名单里(很好的解决了权限滥用的问题想要使用提权操作必须root授权这样其实也方便快速找到是谁出了问题)sudo vs su 主要区别对比特性sudosu认证方式使用当前用户密码使用目标用户密码权限粒度可精细控制每个命令获得完整的目标用户会话日志记录有详细的命令日志只有切换用户记录默认行为执行单条命令开启新的shell会话配置文件/etc/sudoers无独立配置安全性更高最小权限原则较低全权访问使用场景临时执行特权命令需要长时间以目标用户工作示例代码语言javascriptAI代码解释# 初始状态 [haha_118bite-aticloud ~]$ lt total 4 drw.rw.r-x 2 haha_118 haha_118 4096 Oct 22 19:01 dir -rw-rw-r-- 1 haha_118 haha_118 0 Oct 22 19:01 haha.txt # 切换到 root 用户输入root的密码 [haha_118bite-aticloud ~]$ su - Password: [rootbite-aticloud ~]# whoami root # root 用户操作检查并编辑 sudoers 文件将haha_118 用户添加到了 sudoers 配置 #这个具体的操作后面再讲 [rootbite-aticloud ~]# ls /etc/sudoers /etc/sudoers [rootbite-aticloud ~]# vim /etc/sudoers # 返回普通用户使用 sudo 权限 [rootbite-aticloud ~]# logout [haha_118bite-aticloud ~]$ whoami haha_118 [haha_118bite-aticloud ~]$ sudo touch test.txt [sudo] password for haha_118:1.2 三类访问者文件权限的 “身份标签”每个文件 / 目录都有三类 “访问者(角色身份)”对应不同的权限范围这是权限控制的核心uUser所有者文件的创建者如hello.txt的所有者是whb对文件权限拥有最高控制权gGroup所属组文件归属的用户组如hello.txt属于whb组同组用户共享组权限oOthers其他用户既不是所有者也不在所属组的用户如系统中的yhr用户权限最严格通过ls -l可直接查看文件的 “身份标签”示例代码语言javascriptAI代码解释# 格式文件类型 权限 硬链接数 所有者 所属组 大小 时间 文件名 [whbbite-alicloud ~]$ ls -l hello.txt -rw-rw-r-- 1 whb whb 29 Oct 22 20:56 hello.txt # 解读所有者whb所属组whb其他用户表达hello.txt文件的拥有者是whb具有读写的权限。所属组是whb具有读写的权限。others其它用户具有读的权限1.3 三种基本权限读、写、执行Linux 为文件 / 目录定义了三种基本权限不同权限对应不同操作能力且对 “文件” 和 “目录” 的含义不同权限符号数字值对文件的作用对目录的作用r读4查看文件内容如cat列出目录内文件如lsw写2修改文件内容如vim,echo创建/删除/移动目录内文件如touchx执行1运行文件如./script.sh进入目录如cd-无0无法查看文件内容无法列出目录内容或进入目录带了x的不一定就是可执行了还需要它本身就是一个可执行文件才行。整体图示理解二. 权限的两种表示法符号与数字权限有 “符号表示法”直观易懂和 “数字表示法”高效简洁两种实际使用中可根据场景选择2.1 符号表示法精准调整单个权限格式chmod [访问者][±][权限]文件名其中增加权限-删除权限强制设置权限访问者u**所有者、**g**所属组、**o**其他用户、**a**所有用户**。操作示例代码语言javascriptAI代码解释# 1. 给所有者u增加执行x权限 [whbbite-alicloud ~]$ chmod ux hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rwxrw-r-- 1 whb whb 29 Oct 22 20:56 hello.txt # u权限从rw-变为rwx # 2. 给所属组g删除写w权限 [whbbite-alicloud ~]$ chmod g-w hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rwxr--r-- 1 whb whb 29 Oct 22 20:56 hello.txt # g权限从rw-变为r-- # 3. 给其他用户o增加读写权限orw [whbbite-alicloud ~]$ chmod orw hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw----rw- 1 whb whb 29 Oct 22 20:56 hello.txt # 其他用户权限变为rw- # 4. 给其他用户o强制设置读写rw权限 [whbbite-alicloud ~]$ chmod orw hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rwxr--rw- 1 whb whb 29 Oct 22 20:56 hello.txt # o权限从r--变为rw-2.2 数字表示法快速设置所有权限由于r4、w2、x1可将三类访问者的权限用 “三位八进制数字” 表示所有者 所属组 其他用户格式chmod 数字权限 文件名常见权限组合及示例参考数字权限符号权限含义所有者-所属组-其他用户适用场景755rwxr-xr-x所有者读写执行组和其他读执行可执行脚本、公共目录644rw-r–r–所有者读写组和其他只读普通文档、配置文件700rwx------所有者读写执行组和其他无权限私密文件、个人脚本600rw-------所有者读写组和其他无权限敏感配置如密钥文件777rwxrwxrwx所有用户读写执行临时共享目录谨慎使用400r--------仅所有者可读其他无权限只读私密文件如证书示例代码语言javascriptAI代码解释# 数字法将hello.txt权限设为600仅所有者读写 [whbbite-alicloud ~]$ chmod 600 hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw------- 1 whb whb 29 Oct 22 20:56 hello.txt # 权限重置为rw-------整体图示理解补充身份匹配只匹配一次比如whb又是文件的所有者又是所属组那如果他所有者的权限没有w(写)就算所属组的权限有写也没用只匹配一次三. 权限实战修改与验证掌握了权限的 “身份” 和 “表示法”接下来通过chmod改权限、chown改所有者、chgrp改所属组三大命令实战操作并验证效果3.1 修改权限chmod命令chmod是修改权限的核心命令支持符号法和数字法(前面其实已经用过了)且可通过-R递归修改目录权限含子目录和文件。示例 1修改单个文件权限代码语言javascriptAI代码解释# 符号法给hello.txt的所有用户a增加读权限 [whbbite-alicloud ~]$ chmod ar hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw-rw-r-- 1 whb whb 29 Oct 22 20:56 hello.txt # 所有用户均有读权限 # 数字法将hello.txt权限设为600仅所有者读写 [whbbite-alicloud ~]$ chmod 600 hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw------- 1 whb whb 29 Oct 22 20:56 hello.txt示例 2递归修改目录权限代码语言javascriptAI代码解释# 递归设置test目录及其子文件权限为755所有者全权限其他只读执行 [whbbite-alicloud ~]$ chmod -R 755 test [whbbite-alicloud ~]$ tree -p test # 查看目录内权限 test ├── [drwxr-xr-x] subdir │ └── [-rwxr-xr-x] script.sh └── [-rwxr-xr-x] readme.txt3.2 修改所有者与所属组chown与chgrpchown修改文件 / 目录的所有者需 root 权限或文件所有者chgrp修改文件 / 目录的所属组需 root 权限或文件所有者chown需要别人接受才行上面的chmod不用(这个相当于改自己的东西chown相当于给别人东西得经过别人接受)。当然如果是root账户的话不受限制或者使用sudochgrp的话分情况来看操作示例代码语言javascriptAI代码解释# 1. root将hello.txt的所有者改为zpw普通用户无此权限 [rootbite-alicloud ~]$ chown zpw hello.txt [rootbite-alicloud ~]$ ls -l hello.txt -rw------- 1 zpw whb 29 Oct 22 20:56 hello.txt # 所有者从whb变为zpw # 2. 普通用户whb直接修改无sudo权限不足报错 [whbbite-alicloud ~]$ chown whb hello.txt chown: changing ownership of hello.txt: Operation not permitted # 3. 普通用户whb用sudo修改hello.txt的所有者为litao需输入whb自己的密码且whb已在sudoers配置中 [whbbite-alicloud ~]$ sudo chown litao hello.txt [sudo] password for whb: # 输入whb的密码 [whbbite-alicloud ~]$ ls -l hello.txt -rw------- 1 litao zhangsan 29 Oct 22 20:56 hello.txt # 所有者从zpw变为litao # 4. 修改hello.txt的所属组为zhangsan需root或所有者 [rootbite-alicloud ~]$ chgrp zhangsan hello.txt [rootbite-alicloud ~]$ ls -l hello.txt -rw------- 1 zpw zhangsan 29 Oct 22 20:56 hello.txt # 所属组从whb变为zhangsan # 5. 假设whb是hello.txt的所有者且属于zhangsan组主组或附加组 [whbbite-alicloud ~]$ chgrp zhangsan hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw-rw-r-- 1 whb zhangsan 29 Oct 22 20:56 hello.txt # 所属组从原组变为zhangsan # 6. 普通用户whb(此时他不是文件的所有者且目标组不在自身组列表中)用sudo修改hello.txt的所属组为whb组 [whbbite-alicloud ~]$ sudo chgrp whb hello.txt [whbbite-alicloud ~]$ ls -l hello.txt -rw------- 1 litao whb 29 Oct 22 20:56 hello.txt # 所属组从zhangsan变为whb关于所属组的一些补充 这里关于添加组啥的操作就不演示了文末的思维导图里有大家感兴趣也可以自己下去查阅学习一下现在来说组操作其实用的也比较少了3.3 验证权限模拟不同用户操作权限是否生效需通过不同用户的实际操作验证。以 “目录写权限导致文件被删” 为例理解权限的实际影响代码语言javascriptAI代码解释# 1. root设置/home目录为777所有用户可写 [rootbite-alicloud ~]$ chmod 777 /home [rootbite-alicloud ~]$ ls -ld /home drwxrwxrwx. 3 root root 4096 Oct 22 15:58 /home # 2. root在/home创建root.c所有者为root [rootbite-alicloud ~]$ touch /home/root.c [rootbite-alicloud ~]$ ls -l /home/root.c -rw-r--r--. 1 root root 0 Oct 22 15:59 /home/root.c # 3. 普通用户litao删除root.c因/home有写权限成功删除 [rootbite-alicloud ~]$ su - litao [litaolocalhost ~]$ rm /home/root.c rm: remove regular empty file /home/root.c? y # 确认删除 [litaolocalhost ~]$ ls /home/root.c # 验证删除 ls: cannot access /home/root.c: No such file or directory

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询