Linux第二周学习笔记(8)

Linux第二周学习笔记(8)linux


2.14 文件或目录权限chmod ssh

(1). 权限表示ide

[root@daizhihong01 ~]# ls -l学习

总用量 12spa

-rw-------. 1 root root 1418 1月  22 08:19 anaconda-ks.cfgthree

-rw-r--r--  1 root root 4358 1月  29 23:24 anaconda-ks.cfg.1进程

文件的权限是和全部者、所属组有关系的,一个文件总共有三个权限位总共有9位分红三段,加上第一位表示设备类型总共十位,一下进行解析:ci

-rw-r--r-- 文档

第一位“-”:表示设备类型字符串

d:表示目录

-:表示普通文件(包含文本文档及带色标记的二进制文档)

c: 表示字符串的设备(如:鼠标、键盘)

l:软件链接或者硬链接文件(软链接至关于一个快捷方式)

s:通信文件(如:进程相互间的通信)

rw-r--r--(从第二位开始表示权限)

w:是否可写(-不可写);r:是否可读(-不可读);x:是否可执行;

-:不可执行。

第一组rw-:表示全部者(root),文件是谁全部。

rw-表示:r可读,w可写,-不可执行。

第二组-r--:表示所属组(root),文件是属于那一个用户组。

r--表示:r可读,-不可写,-不可执行。

第三组r--:表示其它用户,除了全部者、全部组之外的其它用户

r--表示:r可读,-不可写,-不可执行。

权限使用数字表示:

r=4   w=2   x=1

rwx=7(三个数字相加之和)表示可读可写可执行

rw-=6可读可写不可执行

--x=1只可执行

rw-r--r--=664

rw-r-xr-x=655

-rw-------.在这权限当中最后一位有一个“.”是表明什么意思,意味着这个文件受制于seLinux,若是seLinux开启的话建立的目录最后一位就会有一个“.”。可以使用getenforce命令暂时关闭,若是要彻底关闭的话须要更改配置文件vi /etc/seLinux/config

-----------------------------------------------------------------------------------------

"/etc/selinux/config" 14L, 547C

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=enforcing(更改成disabled便可)这节课这里只作了解,不作任何更改

# SELINUXTYPE= can take one of three two values:

#     targeted - Targeted processes are protected,

#     minimum - Modification of targeted policy. Only selected processes are protected.

#     mls - Multi Level Security protection.

"/etc/selinux/config" 36L, 1133C

-----------------------------------------------------------------------------------------

(2.).chmod命令:chmod命令用来变动文件或目录的权限。在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种通常权限来区分,另有3种特殊权限可供运用。用户能够使用chmod指令去变动文件与目录的权限,设置方式采用文字或数字代号皆可。符号链接的权限没法变动,若是用户对符号链接修改权限,其改变会做用在被链接的原始文件。

chmod-R命令:chmod命令只是对文件或者目录生效的仅仅只是指定的这个目录自己,若是要把目录下面的子目录还有子文件所有一次性批量更改的权限,就要使用-R参数

---------------------------------------------------------------------------------------

chmod命令更改权限:新建123.txt文件进行权限更改,权限更改成:全部者可读、可写、可执行,用户组不可读、不可写、不可执行,其它用户不可读、不可写、不可执行;权限表示以下:rwx------=700

[root@daizhihong01 ~]# touch 123.txt

[root@daizhihong01 ~]# ls

123.txt  anaconda-ks.cfg  anaconda-ks.cfg.1

[root@daizhihong01 ~]# ls -l

总用量 12

-rw-r--r--  1 root root    0 1月  30 20:53 123.txt

-rw-------. 1 root root 1418 1月  22 08:19 anaconda-ks.cfg

-rw-r--r--  1 root root 4358 1月  29 23:24 anaconda-ks.cfg.1

[root@daizhihong01 ~]# chmod 700 123.txt

[root@daizhihong01 ~]# ls -l

总用量 12

-rwx------  1 root root    0 1月  30 20:53 123.txt

-rw-------. 1 root root 1418 1月  22 08:19 anaconda-ks.cfg

-rw-r--r--  1 root root 4358 1月  29 23:24 anaconda-ks.cfg.1

更改daizhihong3权限表示以下:drwxr-xr-x

u (User):即文件或目录的拥有者;

g( Group):即文件或目录的所属群组;

o (Other):除了文件或目录拥有者或所属群组以外,其余用户皆属于这个范围;

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxr-x--x  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

-rw-------. 1 root root    0 1月  22 08:14 yum.log

[root@daizhihong01 tmp]# chmod u=wxr,g=xr,o=rx daizhihong3(在录入的时候是不能加“-”)

 [root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxr-xr-x  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

使用chmod三组权限所有加权限:

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

d-wx--x---  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

[root@daizhihong01 tmp]# chmod a+r daizhihong3(三组权限所有加r,a表明所有)

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxr-xr--  3 root root   24 1月  28 21:58 daizhihong3(所有都加上了r)

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

使用chmod三组权限所有减权限:

 [root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxr-xr--  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

 [root@daizhihong01 tmp]# chmod a-r daizhihong3(三组权限所有减r,a表明所有)

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

d-wx--x---  3 root root   24 1月  28 21:58 daizhihong3(三组权限所有减r)

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

也能够这样使用:

chmod u+r daizhihong3

chmod u-r daizhihong3

chmod g+r daizhihong3

chmod g-r daizhihong3

chmod o+r daizhihong3

chmod o-r daizhihong3

--------------------------------------------------------------------------------

在前面讲密钥认证的时候,在作密钥认证的时候就用到过以下:

[root@daizhihong01 ~]# chmod 700 /root/.ssh

[root@daizhihong01 ~]# ls -ld /root/.ssh/

drwx------. 2 root root 48 1月  26 04:29 /root/.ssh/

--------------------------------------------------------------------------------------------

chmod-R命令: chmod命令只是对文件或者目录生效的仅仅只是指定的这个目录自己,若是要把目录下面的子目录还有子文件所有一次性批量更改的权限,就要使用-R参数

未加R参数:

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxr-xr-x  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

 [root@daizhihong01 tmp]# ls -l daizhihong3

总用量 0

 [root@daizhihong01 tmp]# chmod 770 daizhihong3(更改daizhihong3权限成770rwxrwx---)

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxrwx---  3 root root   24 1月  28 21:58 daizhihong3(更改为功)

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

[root@daizhihong01 tmp]# ls -l daizhihong3

总用量 0

drwxr-xr-x 2 root root 20 1月  28 21:58 daizhihong(可是在daizhihong3下面的子目录权限并未更改)

加R参数:

[root@daizhihong01 tmp]# chmod -R 770 daizhihong3

[root@daizhihong01 tmp]# ls -l

总用量 8

-rw-r--r--  1 root root 2564 1月  29 23:22 anaconda-ks.cfg.1

drwxr-xr-x  2 root root   20 1月  29 13:36 daizhihong

drwxrwx---  3 root root   24 1月  28 21:58 daizhihong3

drwxr-xr-x  5 root root   53 1月  29 11:43 daizhong

 [root@daizhihong01 tmp]# ls -l daizhihong3

总用量 0

drwxrwx--- 2 root root 20 1月  28 21:58 daizhihong(加入-R参数后连着子目录或者子文件的权限一块儿更改)

-------------------------------------------------------------------------------------- 

相关文章
相关标签/搜索