1. 程式人生 > >20181126檔案許可權管理之:高階許可權suid

20181126檔案許可權管理之:高階許可權suid

檔案許可權管理之:高階許可權suid

[[email protected] ~]# touch /root/file1.txt
[[email protected] ~]# ll /root/file1.txt
-rw-r--r--. 1 root root 0 11月 9 09:02 /root/file1.txt

[[email protected] ~]$ cat /root/file1.txt
cat: /root/file1.txt: 許可權不夠
問題:為什麼會失敗?
[[email protected] ~]$ ll -d /root
dr-xr-x---. 28 root root 4096 11月 9 09:04 /root 因為無法進入到root目錄
分析:


[[email protected] ~]$ which cat
/bin/cat 這個程序的所有者是dong1,/root,無法訪問
普通使用者可以修改密碼:
[[email protected] ~]$ passwd
更改使用者 dong1 的密碼 。
為 dong1 更改 STRESS 密碼。
(當前)UNIX 密碼:

[[email protected] ~]# ps aux |grep passwd
root 2130 0.3 0.1 168188 2140 pts/1 S+ 09:17 0:00 passwd 實際上程序的執行者是root

[[email protected] ~]# which passwd
/usr/bin/passwd
[

[email protected] ~]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 30768 2月 22 2012 /usr/bin/passwd
20181126檔案許可權管理之:高階許可權suid

示例:普通使用者勇過suid授權(針對檔案)
在程序檔案(二進位制、可執行)上增加suid許可權
1.[[email protected] ~]# which cat
/bin/cat
[[email protected] ~]# chmod u+s /bin/cat
[[email protected] ~]# which rm

[[email protected] ~]$ cat /root/file1.txt 現在可以正常顯示檔案
1233345664646464789797979sflsjflsjfl

2.[[email protected] ~]$ rm -rf /root/file1.txt
rm: 無法刪除"/root/file1.txt": 許可權不夠
[[email protected] ~]# which rm
alias rm='rm -i'
/bin/rm
[[email protected] ~]# chmod u+s /bin/rm

[[email protected] ~]$ rm -rf /root/file1.txt 已經刪除