在使用RAKsmart美国服务器时,如果安装的是Linux操作系统的话,那么我们经常需要对文件的一些权限进行更改设置。常见的Linux系统文件主要有读、写、执行等权限。
之所以把这部份的内容单列出来,是因为这部份内容是基于我们对RAKsmart Linux美国服务器用户管理及文件权限了解的基础上进行的。比如一个文件的读、写、执行权限,它究竟受到哪些因素影响呢?
首先,一个文件能不能被读取,要受到它的属主、属组及其它用户权限的影响,还要受到其父目录权限的影响。下面简单举个例子:
[root@localhost ~]# cd /home 注:进入/home 目录;
[root@localhost home]# mkdir redhatdir 注:创建一个目录redhatdir
[root@localhost home]# touch redhatdir/test.txt 注:创建一个文件test.txt
[root@localhost home]# chmod 700 redhatdir/ 注:修改redhatdir的权限 ,为属主可读可写可执行,属组和其它用户无权限;
[root@localhost home]# ls -ld redhatdir/ 注:查看redhatdir的属性;
drwx—— 2 root root 4096 04-25 13:01 redhatdir/
[root@localhost home]# ls -lr redhatdir/ 注:查看test.txt 文件的属性;
总计 0
-rw-r–r– 1 root root 0 04-25 13:02 test.txt
[root@localhost home]# su beinan 注:我们切换到普通用户beinan
[beinan@localhost home]$ cd redhatdir/ 注:进入redhatdir目录,以beinan用户身份。
bash: cd: redhatdir/: 权限不够
[beinan@localhost home]$ more redhatdir/test.txt
redhatdir/test.txt: 权限不够
解释:通过以上例子来看,为什么test.txt在其它用户权位上拥有可读权限r–,但我们用普通用户还不能查看它的内容呢?这是因为他的父目录没有其它用户的何读权限。我们是不是redhatdir目录的其它用户可读权限打开,就能让普通用户beinan能读取 test.txt的内容了呢?
[root@localhost home]# chmod 704 redhatdir/
[root@localhost home]# ls -ld redhatdir/
drwx—r– 2 root root 4096 04-25 13:02 redhatdir
[root@localhost home]# su beinan
[beinan@localhost home]$ cd redhatdir/
bash: cd: redhatdir/: 权限不够
看来如果不设置属组的权限,只打开属主的权限及其它用户在redhatdir目录的读权限的情况下,其它用户是不能访问的;我们应该把test.txt父目录的 redhatdir 的属主的读、写、执行要打开,还要把父目录的属组的读和执行权限打开,其它用户的读和执行权限打开,也就是要拥有 rwxr-xr-x 权限,这样文件的其它用户才能访问。
[root@localhost home]# chmod 755 redhatdir/
[root@localhost home]# more redhatdir/test.txt
这里就简单的说说,如果大家看不太明白,可以多多chmod 练习练习(Linux系统之Chown命令用法介绍),也没有什么难的。
其实为文件分配权限的最终目的是让文件的属主有何权限,让属组下的用户有何权限,让其它用户有何权限。文件权限是和用户管理相关联的,所以理解这方面的内容还得了解用户管理。
总之,在平时使用Linux操作系统的美国服务器时,文件的读、写、执行权限是我们经常要做的事情。而且掌握影响读写执行权限的因素也很重要,所以大家应该对这块也应该加以了解。