1. 程式人生 > >Linux用戶、組和權限管理

Linux用戶、組和權限管理

執行 獲取 ica 一起 swd shel document 註意 ttr

Linux-用戶和權限管理

一、用戶和組

早期的計算機的使用場景,一般都是多用戶,多任務下( Multi-task,Multi-Users)。為了區別不同的使用者,隔離每個人對計算機資源的訪問,引入了用戶的概念。

不同的使用者通過用戶標識和密碼加以區別,

認證:Authentication

授權:Authorization

審計:Audition(Account)

這就是3A認證

Linux下的用戶標識就是:用戶

組,即用戶組,用戶容器。

1、用戶類別

用戶分為管理用戶和普通用戶,其中普通用戶又包括系統用戶和登錄用戶

系統用戶:為了能夠讓後臺進程或服務類進程以非管理員身份運行,通常需要為此創建多個普通用戶,這類用戶從不登錄系統

      1、管理用戶
      2、普通用戶
          a.系統用戶
          b.登錄用戶
2、用戶標識
  用戶標識:UserID,UID
        16bits二進制數字:0+65535
              管理員:0
              普通用戶:1-65535
                    系統用戶:1-499(CentOS6),1-999(CentOS7)
                    登錄用戶:500-60000(CentOS6),10000-60000(CentOS7)

        名稱解析:名稱轉換
            Username <--> UID 

            根據名稱解析庫進行: /etc/passwd
3、組類別

和用戶相對應的,組分為管理員組和普通用戶組,普通用戶組又包括系統組和登錄組

      1、管理員組
      2、普通用戶組
          a、系統組
          b、登錄組
4、組標識
   組標識:GroupID,GID
              管理員組:0
              普通用戶組:1-65535
                    系統用戶組:1-499(CentOS6),1-999(CentOS7)
                    登錄用戶組:500-60000(CentOS6),10000-60000(CentOS7)   

        名稱解析:groupname <--> GID
            解析庫: /etc/group
5、組的另外兩種分類方法
  1. A、用戶的基本組:primary group,也叫主組

    B、用戶的附加組

  2. A、私有組:組名同用戶名且包含一個用戶:privite group

    B、公共組:組內包含了多個用戶:public group

6、計算機是如何認證用戶所提供的信息是否真實的?

認證信息:通過比對事先存儲的,與登錄時提供的信息是否一致;

password的存儲位置:

            /etc/shadow     用戶密碼
            /etc/gshadow    組密碼
7、密碼
       密碼的使用策略
           1:使用隨機密碼:
           2:最短長度不要低於8位
           3:應該使用大寫字母,小寫字母、數字和標點符號四類字符中至少三類
           4:定期更換

      密碼存儲格式:單向加密,並借助於salt完成
       加密算法:
           1、對稱加密:加密和解密使用同一個秘鑰
           2、非對稱加密:加密和解密使用的一對兒秘鑰;
                秘鑰對兒:  
                  公鑰:public key
                  私鑰:privita key
           3、單向加密:只能加密,不能解密;提取數據特征碼;
                定長輸出
                雪崩效應

                單向加密常用算法:
                     md5: message digest, 128bits
                     sha: secure hash algorithm,160bits 安全的哈希算法
                     sha224
                     sha256
                     sha384
                     sha512

              在計算之時加salt,添加的隨機數

二、用戶和組管理

1、組管理命令
(1)groupadd命令: 添加組
groupadd [選項] group_name

        -g GID: 指定GID;如不指定會默認,上一個組的GID+1
        -r:創建系統組;                
(2)groupmod命令:修改組屬性
groupmod [選項] GROUP

        -g GID, 修改GID
        -n new_name: 修改組名
(3)groupdel命令: 刪除組

? groupdel [選項] GROUP

(4)gpasswd命令:修改組密碼

組密碼文件: /etc/gshadow

gpasswd [選項] group

          (1)gpasswd group: 修改指定組的密碼,默認情況下組創建之後沒有密碼,設定密碼主要用途在用newgrp命令臨時切換用戶到某個組作為自己的基本組時使用,如果用戶實現不屬於該組,切該組沒有設定密碼,用戶將無法切換到此沒有設定密碼的組
            -a USERNAME:向組中添加用戶
            -d USERNAME:從組中移除用戶
(5)newgrp命令:臨時切換指定的組為基本組
newgrp [-] [group]
         -:會模擬用戶重新登錄以實現重新初始化其工作環境
2、用戶管理命令
(1)useradd命令:添加用戶
      useradd [選項] 登錄名
          -u, --uid UID: 指定UID;如不指定默認為上一個UID+1
          -g, --gid GROUP:指定用戶基本組ID或組名,此組得事先存在
          -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]: 指定用戶所屬的附加組(可以是組ID也可以是組名),多個組之間用逗號分隔;
          -c, --comment COMMENT:指明註釋信息
                       任何字符串。通常是關於登錄的簡短描述,當前用於用戶全名。
          -d, --home HOME_DIR:以指定的路徑作為用戶的家目錄:通過復制/etc/skel此目錄並重命名實現;指定的家目錄路徑如果事先存在,則不會為用戶復制環境配置文件
          -s, --shell SHELL: 指定用戶的默認shell,可用的所有shell列表存儲在/etc/shells文件中;
          -r,創建一個系統用戶
          -M, --no-create-home    不創建用戶主目錄,即使系統在 /etc/login.defs中的設置(CREATE_HOME)為yes
                Do not create the user‘s home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes.
          -f, --inactive INACTIVE
                   密碼過期到賬戶被禁用之前的天數。0表示立即禁用,-1表示禁用這個功能
                                  如果未指定,useradd將使用在 /etc/default/useradd 中 INACTIVE 變量指定的默認禁用周期,或者默認為-1.

        註意:創建用戶是的諸多默認設定配置文件為/etc/login.defs
              -d選項指定家目錄時,家目錄的父目錄需要事先存在,例如指定家目錄為/users/username   父目錄/users需事先存在(被創建)

        useradd -D:顯示創建用戶的默認配置;
        useradd -D 選項:修改默認選項的值;

                修改的結果保存於/etc/default/useradd文件中;也可以通過直接編輯此文件實現
(2)usermod命令:修改用戶屬性
     usermod [選項] 登錄名
             -u,--uid UID: 修改用戶的ID為此處指定的新的UID;
             -g, --gidGROUP:  修改用戶所屬的基本組;此組必須存在;
             -G, --groupsGROUP1[,GROUP2,...[,GROUPN]]]: 修改用戶所屬的附加組;原來的附加組會被覆蓋;
             -a, --append: 與-G一同使用,用於為用戶追加新的附加組;  -aG
             -c, --comment COMMENT: 修改註釋信息;
             -d, --home HOME_DIR: 修改用戶的家目錄: 用戶原有的文件不會被轉移至新位置;
             -m, --move-home: 只能與-d選項一同使用,用於將原來的家目錄裏面的所有文件移動到新的家目錄,目前的家目錄路徑必須存在,否則新家目錄不會被創建;
             -l, --login NEW_LOGIN:修改用戶名;
             -s, --shell SHELL:修改用戶的默認shell;
             -L,--lock:鎖定用戶密碼;即在用戶原來的密碼字符串之前添加一個"!";
             -U,--unlock:解鎖用戶的密碼;
(3)userdel命令:刪除用戶
     userdel [選項] 登錄名
             -r: 刪除用戶是一並刪除其家目錄
(4)passwd命令:修改用戶密碼
 passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username]

          (1)passwd:修改用戶自己的密碼;
          (2)passwd USERNAME:修改指定用戶的密碼,但默認情況下僅root有此權限;

             -l,-u: 鎖定和解鎖用戶密碼
             -d:刪除用戶密碼
             -e DATE: 過期期限,日期
             -i DAYS: 非活動期限;密碼過期之後還能活動幾天
             -n DAYS: 密碼的最短使用期限
             -x DAYS: 密碼的最長使用期限
             -w DAYS: 警告期限

             --stdin:
                 echo "PASSWORD" | passwd --stdin USERNAME
(5)chage命令:更改用戶密碼過期信息
         chage [選項] 登錄名

             -d
             -E
             -W
             -M
             -m
(6)id命令:顯示用戶的真是和有效ID
      id - print real and effective user and group IDs

           id [OPTION]... [USER]
             -u: 僅顯示有效的UID
             -g: 僅顯示用戶的基本組ID
             -G: 顯示用戶所屬的所有組的ID,包括基本組和附加組
             -n: 顯示名字而非ID
(7)su命令:切換用戶
a.登錄式切換:會通過讀取目標用戶的配置文件來重新初始化
su - USERNAME
su -l USERNAME

b.非登陸式切換:不會讀取目標用戶的配置文件進行初始化
su USERNAME

註意:管理員(root)可無密碼切換至其他任何用戶;

      -c ‘COMMAND‘: 僅以指定用戶的身份運行此處指定的命令;運行一次之後直接退回
(8)其他命令
   chsh,  更改默認shell
   chfn,finger  更改finger信息,顯示finger信息
   whoami
   pwck,檢查用戶密碼
   grpck,檢查組

三、權限管理

1.概念

權限的概念:rwx

r:readable,可讀
w:writeable,可寫
x:excuteable,可Z執行

linux權限的表示結構

            rwxrwxrwx:
                左三位:定義user(owner)的權限
                中三位:定義group的權限
                右三位:定義other的權限

進程安全上下文(Security Context)

進程對文件的訪問權限應用模型:

前提:進程有屬主和屬組,文件有屬主和屬組
1、任何一個可執行程序文件能不能運行,取決於發起者對程序文件是否有執行權限。
2、啟動為進程之後,其進程的屬主為發起者,屬組為進程發起者所屬的屬組。
3、進程訪問文件的權限,取決於進程的發起者:
(1)進程的發起者同文件的屬主,則應用文件屬主權限
(2)進程的發起者屬於文件屬組,則應用文件屬組權限
(3)應用其它權限。

rwx對文件和目錄的含義

             文件:
                 r:可獲取文件的數據
                 w:可修改文件的數據
                 x:可將此文件發起運行為進程  

             目錄:
                 r:可使用ls命令獲取其下的所有文件列表;(不能獲取詳細信息,即不包括ls -l)
                 w:可修改此目錄下的文件列表:即創建或刪除文件;
                 x:可cd至此目錄中,且可使用ls -l來獲取所有文件的詳細屬性信息;

權限的兩種表現形式

  1. mode(模型): rwxrwxrwx
  2. ownership(從屬關系):user,group

權限組合機制和八進制表示法

權限的rwx由於在每個位置上只有2種形式,-和其他(r,w,x)即有或沒有權限

因此rwx可以用3位二進制來表示,3位二進制又可以轉換為8進制,組合關系如下

              --- 000 0       沒有權限   0
              --x 001 1       可執行     1
              -w- 010 2       可寫       2
              -wx 011 3
              r-- 100 4       可讀       4
              r-x 101 5
              rw- 110 6
              rwx 111 7

用八位進制權限表示法來表示:如rxwrwxrwx可表示為777,表示屬主屬組和其他用戶都具有讀寫執行的權限

2. 權限管理命令
(1)chmod命令:修改文件權限
               chmod - change file mode bits

                chmod [OPTION]... MODE[,MODE]... FILE...
                chmod [OPTION]... OCTAL-MODE FILE...
                chmod [OPTION]... --reference=RFILE FILE...

             三類用戶:
                  u:屬主
                  g:屬組
                  o:其他
                  a:所有

              chmod [OPTION]... MODE[,MODE]... FILE...

              (1)MODE表示法:

                           A、賦權表示法:直接賦予用戶對應權限,可以操作一類用戶的所有權限位,
                              u=
                              g=
                              o=
                              a=
                              兩種用戶可以合並書寫:ug=,uo=,go=,
                              權限可合並書寫,r,w,x,rw,rwx,rx,wx,

                           B、授權表示法:直接增加或刪除一類用戶的現有權限r,w,x;
                              u+,u-
                              g+,g-
                              o+,o-
                              a+,a-                 (有時候可省略a,直接寫成+,-)

                              兩種用戶可以合並書寫:ug=,uo=,go=,
                              權限也可合並書寫,r,w,x,rw,rwx,rx,wx,
                              盡量符合邏輯書寫,不符合邏輯也不會報錯(例如其他用戶沒有w權限用o-x也不會報錯)
                              分別加不同權限時可以用逗號隔開,如:chmod u+w,g+r FILE

                              ps:全局+w操作只會匹配到u(屬主用戶)

              (2)八進制表示法
                  chmod [OPTION]... OCTAL-MODE FILE...

                  example:
                        chmod 660 /etc/shadow

              (3)引用權限命令
                   chmod [OPTION]... --reference=RFILE FILE...      
                 修改文件FILE的權限與被引用的文件RFILE的權限相同

              選項 :
                  -R,--recurisive:遞歸修改,會將目錄以及目錄下的子目錄和所有文件一起修改  (此選項只建議授權表示法使用,避免影響目錄內部的文件擁有其他不需要的權限,例如錯誤的將x權限給不可執行的文件)

                 註意:用戶僅能修改屬主為自己的那些文件的權限       
    exmaple.                賦權表示
                            [[email protected] ~]# ls
                            00-02-17  a_c  a_d  anaconda-ks.cfg  b_c  b_d  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  桌面
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rw-------. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod g=rw anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rw-rw----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod ug=r anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -r--r-----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod a=rwx anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rwxrwxrwx. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod u=rwx,g=rw,o= anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rwxrw----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg

                            授權表示
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            ----------. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod u+w anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            --w-------. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod ug+r anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rw-r-----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod a+x anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rwxr-x--x. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod -x anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rw-r-----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod u-w anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -r--r-----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg
                            [[email protected] ~]# chmod +w anaconda-ks.cfg 
                            [[email protected] ~]# ll anaconda-ks.cfg 
                            -rw-r-----. 1 root root 1257 3月  19 19:05 anaconda-ks.cfg            //全局+w操作只會匹配到u(屬主用戶),因為全局+w很危險

                            權限引用
                            [[email protected] tmp]# ll | head -3
                            總用量 276
                            -rw-r--r--. 1 root root      0 4月  19 19:16 a
                            -rw-r--r--. 1 root root      0 4月  19 19:16 b
                            [[email protected] tmp]# chmod 766 a
                            [[email protected] tmp]# ll | head -3
                            總用量 276
                            -rwxrw-rw-. 1 root root      0 4月  19 19:16 a
                            -rw-r--r--. 1 root root      0 4月  19 19:16 b
                            [[email protected] tmp]# chmod --reference=a b
                            [[email protected] tmp]# ll | head -3
                            總用量 276
                            -rwxrw-rw-. 1 root root      0 4月  19 19:16 a
                            -rwxrw-rw-. 1 root root      0 4月  19 19:16 b

                            -R選項    
                            [email protected] tmp]# ls -la skel
                            總用量 16
                            drwxr-xr-x.  3 root root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 19:43 ..
                            -rw-r--r--.  1 root root   18 4月  19 19:43 .bash_logout
                            -rw-r--r--.  1 root root  193 4月  19 19:43 .bash_profile
                            -rw-r--r--.  1 root root  231 4月  19 19:43 .bashrc
                            drwxr-xr-x.  4 root root   39 4月  19 19:43 .mozilla
                            [[email protected] tmp]# chmod -R go= skel
                            [[email protected] tmp]# ls -la skel
                            總用量 16
                            drwx------.  3 root root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 19:43 ..
                            -rw-------.  1 root root   18 4月  19 19:43 .bash_logout
                            -rw-------.  1 root root  193 4月  19 19:43 .bash_profile
                            -rw-------.  1 root root  231 4月  19 19:43 .bashrc
                            drwx------.  4 root root   39 4月  19 19:43 .mozilla
                            [[email protected] tmp]# chmod -R g+r skel/
                            [[email protected] tmp]# ls -la skel
                            總用量 16
                            drwxr-----.  3 root root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 19:45 ..
                            -rw-r-----.  1 root root   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 root root  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 root root  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 root root   39 4月  19 19:43 .mozilla
(2)從屬關系管理命令:chown,chgrp

僅管理員可修改文件的屬主和屬組,

chown命令: 既能修改屬主也能修改屬組

    chown [OPTION]... [OWNER][:[GROUP]] FILE...         //修改屬主
    chown [OPTION]... --reference=RFILE FILE...         //引用(參考修改)
        選項:
          -R:遞歸修改     

chgrp命令: 只能用於修改屬組

    chgrp [OPTION]... GROUP FILE...
    chgrp [OPTION]... --reference=RFILE FILE...
                exmple.     修改屬主
                            [email protected] tmp]# ls -la skel
                            總用量 16
                            drwxr-----.  3 root root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 19:45 ..
                            -rw-r-----.  1 root root   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 root root  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 root root  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 root root   39 4月  19 19:43 .mozilla
                            [[email protected] tmp]# chown -R docker skel          
                            [[email protected] tmp]# ll -d skel
                            drwxr-----. 3 docker root 78 4月  19 19:43 skel
                            [[email protected] tmp]# ll -a skel
                            總用量 16
                            drwxr-----.  3 docker root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root   root 4096 4月  19 19:45 ..
                            -rw-r-----.  1 docker root   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 docker root  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 docker root  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 docker root   39 4月  19 19:43 .mozilla

                            修改屬主和屬組
                            [[email protected] tmp]# ll -a skel/
                            總用量 16
                            drwxr-----.  3 docker root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root   root 4096 4月  19 19:55 ..
                            -rw-r-----.  1 docker root   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 docker root  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 docker root  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 docker root   39 4月  19 19:43 .mozilla
                            [[email protected] tmp]# chown -R jacky:docker skel/
                            [[email protected] tmp]# ll -a skel/
                            總用量 16
                            drwxr-----.  3 jacky docker   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root  root   4096 4月  19 19:57 ..
                            -rw-r-----.  1 jacky docker   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 jacky docker  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 jacky docker  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 jacky docker   39 4月  19 19:43 .mozilla
                            [[email protected] tmp]# chown -R root.root skel/
                            [[email protected] tmp]# ll -a skel/
                            總用量 16
                            drwxr-----.  3 root root   78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 19:57 ..
                            -rw-r-----.  1 root root   18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 root root  193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 root root  231 4月  19 19:43 .bashrc
                            drwxr-----.  4 root root   39 4月  19 19:43 .mozilla

                            引用(參考)修改
                            [[email protected] tmp]# ll a
                            -rwxrw-rw-. 1 tom tom 0 4月  19 19:16 a
                            [[email protected] tmp]# chown -R --reference=a /tmp/skel/
                            [[email protected] tmp]# ll -a skel/
                            總用量 16
                            drwxr-----.  3 tom  tom    78 4月  19 19:43 .
                            drwxrwxrwt. 24 root root 4096 4月  19 20:02 ..
                            -rw-r-----.  1 tom  tom    18 4月  19 19:43 .bash_logout
                            -rw-r-----.  1 tom  tom   193 4月  19 19:43 .bash_profile
                            -rw-r-----.  1 tom  tom   231 4月  19 19:43 .bashrc
                            drwxr-----.  4 tom  tom    39 4月  19 19:43 .mozilla

思考:用戶對目錄有寫權限,但對目錄下的文件沒有寫權限時,

(1)能否修改目錄下的文件? 不能。

(2)能否刪除目錄下的文件? 可以

umask:文件權限反向掩碼,遮罩碼

用戶擁有自己的umask,用戶創建文件後,文件的默認權限如下:

        文件的權限:
            666-umask
        目錄的權限:
            777-umask
        註意:之所以文件用666去減,表示文件默認不能擁有執行權限;如果減得的結果中有執行權限,則需要將其加1;
            umask:023
                666-023=643+1=644
                777-023=754

? umask命令:

umask: 查看當前umask

umask MASK:設置umask

? 註意:此類設定僅對當前shell進程有效;

(3)install命令:復制文件並設置權限屬性
      install - copy files and set attributes--復制文件並設置屬性

   單源復制:
      install [OPTION]... [-T] SOURCE DEST
   多源復制:
      install [OPTION]... SOURCE... DIRECTORY...
      install [OPTION]... -t DIRECTORY SOURCE...
   創建目錄:   
      install [OPTION]... -d DIRECTORY...

?     
?       常用選項:
?           -m, --mode=MODE: 設定目標文件權限,默認為755
?           -o, --owner=OWNER: 設定目標文件屬主;
?           -g, --group=GROUP: 設定目標文件屬組;
?    example.
?                   [[email protected] tmp]# install /etc/inittab /tmp
?                   [[email protected] tmp]# ls -l inittab 
?                   -rwxr-xr-x. 1 root root 511 4月  19 20:37 inittab
?                   [[email protected] tmp]# ls -l /etc/inittab 
?                   -rw-r--r--. 1 root root 511 8月   4 2017 /etc/inittab
?                   [[email protected] tmp]# rm inittab 
?                   rm:是否刪除普通文件 "inittab"?y
?                   [[email protected] tmp]# install -m 640 /etc/init
?                   init.d/  inittab  
?                   [[email protected] tmp]# install -m 640 /etc/inittab /tmp
?                   [[email protected] tmp]# ls -l inittab 
?                   -rw-r-----. 1 root root 511 4月  19 20:42 inittab
?                   [[email protected] tmp]# install -o jacky -g docker /etc/inittab /root
?                   [[email protected] tmp]# ls -l /root/inittab 
?                   -rwxr-xr-x. 1 jacky docker 511 4月  19 20:44 /root/inittab
?    
            -d選項創建目錄
            [[email protected] tmp]# install -d hello
            [[email protected] tmp]# ll -d hello
            drwxr-xr-x. 2 root root 6 4月  19 20:45 hello
(4)mktemp命令:創建臨時文件
mktemp - create a temporary file or directory 創建臨時文件或臨時目錄

命令格式:mktemp [OPTION]... [TEMPLATE]
       TEMPLATE must contain at least 3 consecutive ‘X‘s in last component(模板文件名中至少包含3個X,(自定義名稱.xxx))

            -d  --directory 創建臨時目錄
            -u  --dry-run   僅做測試,不會實際創建文件
            -q  --執行若發生錯誤,不會顯示任何信息

             註意:mktemp會將創建的臨時文件名直接返回,因此,可直接通過命令引用保存起來;
             使用mktemp 命令生成臨時文件時,文件名參數應當以"文件名.XXXX"的形式給出,mktemp 會根據文件名參數建立一個臨時文件。
             例如:mktemp tmp.xxxx #生成臨時文件 

Linux用戶、組和權限管理