分类: LINUX
2008-11-20 14:34:23
【1. 基本要点】
①文件的访问权限分为:读(r)、写(w)、执行(x)
②文件的被访问对象分为:文件拥有者、用户组、其他人
【2. 关于/和/root目录】
①/目录为根目录,root为超级管理员的根目录
②/目录和root目录的访问权限如下所示:
可以看到这两个目录的用户和用户组都为root所有,/目录下允许用户组和其他用户具有读和执行的权限,而root目录十分重要,所以除了用户和所在的用户组之外,其他用户一律无权查看。
【3. 关于权限x在文件和目录下的不同作用】
①文件:权限x意味着该文件为可执行的
②目录:权限x意味着可以在该目录下执行任何命令
③备注:如果想对他人开放某个目录的话,请记住,开放该目录的x属性。因为如果在该目录下不能执行任何命令的话,那么自然也就无法进入了。
我们来看下面的例子
[paul@localhost /]$ ls -ld testdir/
drwxrwxrwx 2 paul root 4096 11月 18 15:48 testdir/
[paul@localhost /]$ chmod -R 754 testdir/
[paul@localhost /]$ ls -ld testdir/
drwxr-xr-- 2 paul root 4096 11月 18 15:48 testdir/
[paul@localhost /]$ su - oracle
Password:
[oracle@localhost ~]$ cd /
[oracle@localhost /]$ ls -ld testdir/
drwxr-xr-- 2 paul root 4096 11月 18 15:48 testdir/
[oracle@localhost /]$ cd testdir/
-bash: cd: testdir/: 权限不够
我们看到,在将paul用户下的目录testdir访问权限设置为754之后,其它用户对该目录的访问权限只有一个读(r),当我们切换到oracle用户后访问该目录会出现权限不够的错误。此时我们再增加一个执行权限(x)给其它用户,看看结果如何:
[paul@localhost ~]$ cd /
[paul@localhost /]$ chmod -R 755 testdir/
[paul@localhost /]$ su - oracle
Password:
[oracle@localhost ~]$ ls -ld /testdir/
drwxr-xr-x 2 paul root 4096 11月 18 15:48 /testdir/
[oracle@localhost ~]$ cd /testdir/
[oracle@localhost testdir]$
[root@localhost /]# ls -ld /
drwxr-xr-x 25 root root 4096 11月 18 15:20 /
[root@localhost /]# ls -ld testdir/ t1.txt t2.txt
-rwxrwxr-x 1 root root 0 11月 18 15:20 t1.txt
-rw-r--r-- 1 paul root 0 11月 18 15:20 t2.txt
drwxrwxrwx 2 paul root 4096 11月 18 15:48 testdir/
[paul@localhost ~]$ cd /
[paul@localhost /]$ ls -ld testdir/ t1.txt t2.txt
-rwxrwxr-x 1 root root 0 11月 18 15:20 t1.txt
-rw-r--r-- 1 paul root 0 11月 18 15:20 t2.txt
drwxrwxrwx 2 paul root 4096 11月 18 15:48 testdir/
[paul@localhost /]$ rm -rf testdir/
rm: 无法删除目录‘testdir/’: 权限不够
[paul@localhost /]$
[paul@localhost testdir]$ ls -ld t3.txt
-rw-r--r-- 1 root root 0 11月 18 17:06 t3.txt
[paul@localhost testdir]$ rm -f t3.txt