1. 程式人生 > >34.權限管理命令

34.權限管理命令

enc 自己的 sta 定義 .bashrc 參考 files 結果 rac

權限管理命令:
chmod命令:
三類用戶:
u:屬主
g:屬組
o:其他
a:所有


    1. 賦權、授權表示法*

                                  u、g、o、a分別代表:屬主、屬組、其他人、所有人
      
                                +:在原來權限的基礎上增加權限
      
               -:在原來權限的基礎上去除權限
      
                                   =:直接定義權限
      
                                   r、w、x:讀、寫、執行
      
              註意:用戶僅能修改屬主為自己的那些文件的權限;
      
                          實例:
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-r--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod g=rw fstab 
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw-r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod ug=r fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -r--r--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u=rwx,g=rw,o= fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u=rwx,g=rw,o= fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u-x fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod o+r fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw-r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod ug+x fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrwxr--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod g-wx fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxr--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-r--r--. 1 root root 541 2月  23 19:00 fstab
                          [root@itxuezhe tmp]# chmod -r fstab 
                      [root@itxuezhe tmp]# ll fstab
                          --w-------. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u+x,g+w fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          --wx-w----. 1 root root 541 2月  23 19:00 fstab

2.八進制表示法:

技術分享圖片

    實例:

                    [root@itxuezhe tmp]# chmod 666 fstab 
                    [root@itxuezhe tmp]# ll fstab 
                    -rw-rw-rw-. 1 root root 541 2月  23 19:00 fstab

                [root@itxuezhe tmp]# chmod 644 fstab 
                [root@itxuezhe tmp]# ll fstab 
                -rw-r--r--. 1 root root 541 2月  23 19:00 fstab

  1. chmod –reperence=文件1 文件2 // 以文件1的權限為標準修改文件2的權限

        實例:
    
        [root@itxuezhe tmp]# ls -l /var/log/messages 
        -rw-------. 1 root root 1116015 2月  23 19:20 /var/log/messages
    
        [root@itxuezhe tmp]# ll fstab 
        -rwxrw-rw-. 1 root root 541 2月  23 19:00 fstab
    
        **參考/var/log/messages 的權限去修改/tmp/fstab**    
    
      [root@itxuezhe tmp]# ll fstab 
        -rwxrw-rw-. 1 root root 541 2月  23 19:00 fstab
    
        [root@itxuezhe tmp]# chmod --reference=/var/log/messages fstab 
        [root@itxuezhe tmp]# ll fstab 
        -rw-------. 1 root root 541 2月  23 19:00 fstab

                選項:
                    -R:遞歸修改;

                    [root@itxuezhe tmp]# chmod 700 skel/ -R
                    [root@itxuezhe tmp]# ll skel/ -a 
                    總用量 16
                    drwx------.  3 root root   78 2月  23 19:57 .
                    drwxrwxrwt. 21 root root 4096 2月  23 19:59 ..
                    -rwx------.  1 root root   18 2月  23 19:57 .bash_logout
                    -rwx------.  1 root root  193 2月  23 19:57 .bash_profile
                    -rwx------.  1 root root  231 2月  23 19:57 .bashrc
                    drwx------.  4 root root   39 2月  23 19:57 .mozilla

    從屬關系管理命令:chown, chgrp

                chown命令:

                            選項:
                                -R:     

                實例:

                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 itxuezhe itxuezhe 541 2月  23 19:00 fstab

                                [root@itxuezhe tmp]# chown -R root:root fstab 
                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 root root 541 2月  23 19:00 fstab

                                [root@itxuezhe tmp]# chown -R itxuezhe.itxuezhe fstab 
                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 itxuezhe itxuezhe 541 2月  23 19:00 fstab

        **  參考/tmp/tracker-extract-files.1000的屬主和屬組權限修改/tmp/skel/目錄下的文件文件**

        [root@itxuezhe tmp]# ll -d tracker-extract-files.1000/
        drwx------. 2 itxuezhe itxuezhe 6 2月  19 19:01 tracker-extract-files.1000/

        [root@itxuezhe tmp]# chown -R --reference=/tmp/tracker-extract-files.1000/ /tmp/skel/

        [root@itxuezhe tmp]# ll -a skel/
        總用量 16
        drwx------.  3 itxuezhe itxuezhe   78 2月  23 19:57 .
        drwxrwxrwt. 21 root     root     4096 2月  23 20:13 ..
        -rwx------.  1 itxuezhe itxuezhe   18 2月  23 19:57 .bash_logout
        -rwx------.  1 itxuezhe itxuezhe  193 2月  23 19:57 .bash_profile
        -rwx------.  1 itxuezhe itxuezhe  231 2月  23 19:57 .bashrc
        drwx------.  4 itxuezhe itxuezhe   39 2月  23 19:57 .mozilla

                chgrp命令:

                    註意:僅管理員可修改文件的屬主和屬組;

    umask:文件的權限反向掩碼,遮罩碼;
                文件:666 - umask
                目錄:777 - umask

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

                    umask命令:
                                umask:查看當前umask
                                umask ###:設置umask

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

技術分享圖片

34.權限管理命令