標籤:linux 特殊許可權位 sgid suid stid
設定特殊許可權)
SUID
作用:臨時賦予使用者二進位文檔的擁有者的許可權(主要用於讓普通使用者可以使用某些特殊命令)
文法:
chmod u+s file(增加s許可權)
chmod u-s file(減去s許可權)
使用限制與環境:
1、僅對於二進位檔案有效;
2、執行者必須對檔案擁有x許可權,否則,由於無執行許可權,SUID此時無效,此時許可權位顯示S;
3、許可權只是在執行過程中擁有。
========================================================================[[email protected] ~]# su nagios #切換到nagios普通使用者下[[email protected] root]$ lsls: cannot open directory .: Permission denied #普通使用者不可以訪問root家目錄#增加上s許可權[[email protected] ~]# chmod u+s /bin/ls[[email protected] ~]# su nagios[[email protected] root]$ ls -l /bin/ls-rwsr-xr-x. 1 root root 112664 Nov 22 2013 /bin/ls[[email protected] root]$ lsanaconda-ks.cfg dir4 install.log.syslog newdir test11 test33crontab.sh install.log mbr.bin newfile test22#如果沒有執行許可權[[email protected] ~]# chmod u-x /bin/ls[[email protected] ~]# ls -l /bin/ls-rwSr-xr-x. 1 root root 112664 Nov 22 2013 /bin/ls #可看到S出現了#擴充命令file[[email protected] root]$ file /bin/ls/bin/ls: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped#file命令能看到檔案類型,出來的結果和我們前幾節說的type命令不一樣#type命令是專門用來看命令類型的。========================================================================
PS:例如passwd命令,路徑/usr/bin/passwd,許可權為"-rwsr-xr-x"。passwd命令會修改"/etc/shadow",而/etc/shadow對於普通使用者的許可權是不可讀、不可寫、不可執行。
PS:SUID只可用於二進位檔案,不可用於shell script檔案。
SGID
作用:臨時賦予使用者二進位文檔的屬組許可權(和suid類似)
文法
chmod g+s file(增加s許可權)
chmod g-s file(減去s許可權)
使用限制與環境:
1、僅對於二進位檔案有效;
2、執行者必須對檔案擁有x許可權(否則無法執行,SGID此時無效,許可權位顯示S);
3、許可權只是在執行過程中擁有。
PS:例如locate命令,路徑/usr/bin/locate,許可權為"rwx--s--x"。此時普通使用者暫時獲得了root使用者的許可權去執行(locate命令會讀取"/var/lib/mlocate/mlocate.db")
作用:臨時將使用者的effectivegroup修改成該目錄的的群組
文法
chmod g+s dir(增加s許可權)
chmod g-s dir(減去s許可權)
使用限制與環境:
1、使用者必須對該目錄擁有x許可權(否則無法進入,SUID此時無效,許可權位顯示S);
2、若使用者對此目錄擁有w許可權,由於effective group被修改成該目錄的group,所以使用者在此目錄下建立檔案,屬主為使用者本身,屬組為該目錄的使用者組。
SBIT
作用:限制目錄下不同使用者之間對於其他使用者文檔或目錄的編輯許可權。
文法
chmod o+t dir(增加t許可權)
chmod o-t dir(減去t許可權)
使用限制與環境
1、只能針對目錄;
2、必須有x和w許可權(否則無法進入和編輯,此時sbit無效,許可權位顯示T);
3、使用者自身建立的文檔和目錄,只有自己和root可以編輯(重新命名、修改內容、複製、刪除等)
本文出自 “三零妖人” 部落格,請務必保留此出處http://301ren.blog.51cto.com/8887653/1618816
linux基礎:9、檔案特殊許可權