Linux文件管理:root权限与chmod、chgrp、chown操作详解

需积分: 28 5 下载量 185 浏览量 更新于2024-08-25 收藏 74KB PPT 举报
"这篇文档是关于Linux文件管理的总结,主要关注root权限的修改和Linux文件权限的理解。文章提到了如何使用chmod命令改变文件权限,包括直接数字模式和符号模式的使用,以及如何通过chgrp和chown命令修改文件的所有者和组。此外,还简述了root用户的角色和权限,以及umask命令在设置默认权限中的作用。" 在Linux操作系统中,文件和目录的权限管理是至关重要的安全机制。文件权限由一个9位的字符串表示,例如"-rwxr-xr-x",其中第一位标识文件类型(d表示目录,-表示常规文件,l表示链接文件,b和c分别代表块设备和字符设备)。接下来的三位分别代表所有者(user)、所属组(grp)和其他用户(others)的读(read)、写(write)和执行(execute)权限。 `chmod`命令用于改变文件或目录的权限。例如,`sudo chmod 755 test.txt`将使`test.txt`的权限变为所有者可读可写可执行,组和其他用户可读可执行。另外,`sudo chmod u=rwx go=rx test.txt`直接指定用户、组和其他用户的权限,效果与755相同。`sudo chmod a+x test.shell`会给所有用户类别增加执行权限。 `root`用户是Linux中的超级管理员,拥有对所有文件的最高权限,可以更改任何文件的权限和所有者。切换到root用户有两种方法:使用`sudo su`或在命令前加上`sudo`。 `chgrp`和`chown`命令用于修改文件或目录的组和所有者。`chgrp -R root directory`将递归地将`directory`及其所有子项的组更改为`root`,而`chown root:root test.txt`会将文件`test.txt`的所有者和组都设为`root`。 `umask`命令用来设置创建新文件时的默认权限,其返回的值是一个四位数,代表默认要从666(所有者、组和其他用户都有读写权限)中移除的权限位。例如,`umask`返回的值如果是022,则新创建的文件默认权限将是644(rw-r--r--),因为22代表从666中移除了两个用户写的权限位。 理解并熟练掌握这些命令对于有效管理和保护Linux系统中的文件和目录至关重要。通过合理设置权限,可以确保系统的安全性,同时满足不同用户和程序的访问需求。

为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.

2023-06-01 上传