linux|linux 基本权限

一、文件权限
我们以/etc/passwd 文件为例,用ll长列出其属性如下所示

[root@centos6 ~]# ll /etc/passwd
-rw-r–r--. 1 root root 1619 Jan 19 10:39 /etc/passwd
  • –rw–r--r–:代表文件的权限。
    1:代表文件的引用计数
    root:代表文件所有者
    root:代表文件所属组
    1619:代表文件大小
    Jan 19 10:39:代表文件创建时间
    /etc/passwd:代表文件名
每个文件针对每类访问访问者都定义了三种权限
r:Readabel
w:Writable
x:eXcutable
对于文件来说:
r:可以使用文件查看类工具获取其内容w:可以修改其内容x:可以执行此文件

对于目录来说:
r:可以使用ls查看此目录中文件列表w:可以在此目录中创建,删除文件x:可以使用ls -l查看此目录中文件列表,可以进入此目录

linux|linux 基本权限
文章图片

chmod
ch`mod命令用来变更文件或目录的权限。在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种一般权限来区分,另有3种特殊权限可供运用。用户可以使用chmod指令去变更文件与目录的权限,设置方式采用文字或数字代号皆可。符号连接的权限无法变更,如果用户对符号连接修改权限,其改变会作用在被连接的原始文件。`

语法
chmod(选项)(参数)
[root@centos6 ~]# ll /etc/passwd
-rw-r–r--. 1 root root 1619 Jan 19 10:39 /etc/passwd
这里的第一个“-”代表这是个二进制普通文件其他的每三个是一个整体权限如:
rw-:代表的是所属人的权限(rw:读写权限)r--:代表的是所属组的权限 (r--:只读权限)r--:代表的是其他人的权限 (r--:只读权限)

【linux|linux 基本权限】示例:
[root@localhost app]#ll file1 -rw-r--r--. 1 root root 0 Jan 27 17:38 file1 [root@localhost app]#chmod u+x,g+w file1//给文件所属人加上执行权限,给文件所属组加上写权限 [root@localhost app]#ll file1 -rwxrw-r--. 1 root root 0 Jan 27 17:38 file1[root@localhost app]#ll file1 -rwxrw-r--. 1 root root 0 Jan 27 17:38 file1 [root@localhost app]#chmod u=rwx,g=rwx,o=rw file1//让文件所属人有全部权限,让文件所属组有全部权限,让其他人对此文件有读写权限 [root@localhost app]#ll file1 -rwxrwxrw-. 1 root root 0 Jan 27 17:38 file1[root@localhost app]#ll file1 -rwxrwxrw-. 1 root root 0 Jan 27 17:38 file1 [root@localhost app]#chmod 400 file1//用数字方式修改文件权限,让只有文件所属人有读取权限,所属组和其他人对文件没有权限 [root@localhost app]#ll file1 -r--------. 1 root root 0 Jan 27 17:38 file1[root@localhost app]#ll file1 -r--------. 1 root root 0 Jan 27 17:38 file1 [root@localhost app]#chmod u+w file1//给文件加上权限,这里u+w表示给文件所属人加上写权限,同理g+w表示给所属组叫上写权限,o+w表示给其他人加上些权限 [root@localhost app]#ll file1 -rw-------. 1 root root 0 Jan 27 17:38 file1 [root@localhost app]#chmod a+w file1//+w前面不跟参数时默认表示给所属人权限位叫上写权限,a+w表示给所有权限位都加上w权限 [root@localhost app]#ll file1 -rw--w--w-. 1 root root 0 Jan 27 17:38 file

    推荐阅读