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參數後連着子目錄或者子文件的權限一塊兒更改)
--------------------------------------------------------------------------------------