Chinaunix首页 | 论坛 | 博客
  • 博客访问: 124443
  • 博文数量: 38
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 385
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-14 17:13
文章分类

全部博文(38)

文章存档

2009年(3)

2008年(35)

我的朋友

分类: LINUX

2008-11-20 14:34:23

【1. 基本要点】


 ①文件的访问权限分为:读(r)、写(w)、执行(x)
 ②文件的被访问对象分为:文件拥有者、用户组、其他人
 
【2. 关于/和/root目录】
 ①/目录为根目录,root为超级管理员的根目录
 ②/目录和root目录的访问权限如下所示: 
[root@localhost ~]# ls -ld /
drwxr-xr-x  
25 root root 4096 11月 18 15:20
 /
[root@localhost ~]
# ls -ld /root
drwxr-x---  
13 root root 4096 11月 18 15:20 /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]$

【4. 关于权限w的理解】
 ①权限w对于文件来说意味着修改(注意不是删除),对于目录来说则意味这修改和删除
 ②要判断用户对某个文件是否有权修改或删除,不应该看文件本身的权限属性,而应该看文件所在目录的权限属性
   
例如下面的例子:
[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/

我们看到对于/目录,它的权限属性设置是用户组和其他人只能读和执行,而不具备写的权利。而/目录下的testdir目录具备777权限。现在我们尝试在paul用户下删除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 /]$

我们看到删除失败了。为什么?这是因为我们为testdir目录设置的权限属性,是指定testdir目录下的文件的,而不是testdir目录本身。如果我们要删除testdir目录,应该参考用户对其父目录/的权限属性。而从前面中我们已经知道/目录对其它用户的权限为只读,所以当然不能删除testdir了。下面我们试一下能否删除testdir目录下的文件t3.txt

[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

我们看到这个文件是属于root的,但是我们依然可以在paul用户下删除它,原因就是因为我们对testdir这目录设置的权限属性是777,即其它用户也可以对这个目录下的文件进行写操作。
阅读(1098) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~