亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

linux特殊權(quán)限使用(suid、sgid、sbit)

 更新時間:2024年08月26日 11:00:35   作者:草莓田田圈~  
這篇文章主要介紹了linux特殊權(quán)限使用(suid、sgid、sbit),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

一.linux特殊權(quán)限介紹

特殊權(quán)限

在linux系統(tǒng)中,除了r讀w寫x執(zhí)行權(quán)限外,還存在其他的權(quán)限;下圖中在權(quán)限位置上有不同的字母

二.suid

1.介紹suid之前需要了解一些問題

普通用戶是否可以修改密碼

可以修改自己密碼

/etc/shadow文件的作用是什么

存儲用戶密碼的文件

/etc/shadow文件的權(quán)限是什么

普通用戶是否可以修改/etc/shadow文件

不可以修改,沒有任何權(quán)限

為什么普通用戶可以修改密碼

  • 使用了passwd命令
  • passwd在x權(quán)限位上有s權(quán)限
  • 在使用有suid權(quán)限的文件或者命令時,會以該文件的屬主身份去執(zhí)行該命令

2.suid作用詳解

概念:命令文件的x權(quán)限位變?yōu)閟,那么其他用戶執(zhí)行命令文件時,就會以該命令文件的屬主用戶去執(zhí)行

  • 如果屬主權(quán)限位上有x,則會顯示小s
  • 如果屬主權(quán)限位上沒有x,則會顯示大S

實例:

設(shè)置suid,普通用戶可以正常修改自己的密碼,取消suid,普通賬戶無法修改自己的密碼

[root@localhost ~]# useradd tdm  #創(chuàng)建用戶tdm
[root@localhost ~]# passwd tdm   #設(shè)置密碼
Changing password for user tdm.
New password: 
BAD PASSWORD: The password is shorter than 7 characters
Retype new password: 
passwd: all authentication tokens updated successfully.   #設(shè)置密碼成功
[root@localhost ~]# su - tdm   #切換用戶tdm
Last login: Mon Jun  5 11:21:29 CST 2023 on pts/0
[tdm@localhost ~]$ passwd    #修改密碼
Changing password for user tdm.
Changing password for tdm.
(current) UNIX password: 
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.  #修改密碼成功
[tdm@localhost ~]$ exit    #退出登錄
logout
[root@localhost ~]# chmod u-s  /bin/passwd    #修改passwd權(quán)限,取消suid權(quán)限
[root@localhost ~]# ll  /bin/passwd     #查看命令文件權(quán)限
-rwxr-xr-x. 1 root root 27832 Jun 10  2014 /bin/passwd    #s變成了x
[root@localhost ~]# su - tdm    #再次切換tdm賬戶
Last login: Mon Jun  5 11:24:54 CST 2023 on pts/0
[tdm@localhost ~]$ passwd    #修改密碼
Changing password for user tdm.
Changing password for tdm.
(current) UNIX password: 
New password: 
Retype new password: 
passwd: Authentication token manipulation error  #密碼修改失敗

問題:如果普通用戶在使用passwd命令時,是以root的身份去執(zhí)行的,普通用戶是否能修改其他賬戶的密碼

無法修改,只有root在使用passwd命令時后面可以接用戶名稱,其他賬號不可以。

[tdm@localhost ~]$ passwd test    #tdm想修改test的密碼
passwd: Only root can specify a user name.    #只用root賬戶后面才能接用戶名稱

3.授權(quán)、撤銷suid權(quán)限

  • 授權(quán)格式:chmod u+s 文件名稱
  • 撤銷格式:chmod u-s 文件名稱
[root@localhost ~]# touch test.txt    #創(chuàng)建文件
[root@localhost ~]# ll test.txt     #查看文件屬性
-rw-r--r--. 1 root root 0 Jun  5 11:37 test.txt
[root@localhost ~]# chmod u+s test.txt     #授權(quán)suid屬性
[root@localhost ~]# ll test.txt 
-rwSr--r--. 1 root root 0 Jun  5 11:37 test.txt    #文件具有suid屬性
[root@localhost ~]# chmod u-s  test.txt    #文件取消suid屬性
[root@localhost ~]# ll test.txt 
-rw-r--r--. 1 root root 0 Jun  5 11:37 test.txt    #文件取消suid屬性
[root@localhost ~]# chmod 4644 test.txt     #授權(quán)suid屬性
[root@localhost ~]# ll test.txt 
-rwSr--r--. 1 root root 0 Jun  5 11:37 test.txt    #文件具有suid屬性
[root@localhost ~]# chmod 0644 test.txt     #文件取消suid屬性
[root@localhost ~]# ll test.txt 
-rw-r--r--. 1 root root 0 Jun  5 11:37 test.txt    #文件取消suid屬性

三.sgid

1.sgid作用詳解

概念:一般情況下是設(shè)置給目錄使用的,主要目的是讓彼得用戶無法刪除其他用戶所創(chuàng)建的文件或目錄

  • 如果屬主權(quán)限位上有x,則會顯示小s
  • 如果屬主權(quán)限位上沒有x,則會顯示大S

實例:

給目錄設(shè)置了sgid權(quán)限,在該目錄下創(chuàng)建的文件或者目錄的屬組都與該目錄一致

[root@localhost opt]# mkdir abc    #創(chuàng)建目錄abc
[root@localhost opt]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun  5 13:18 abc
[root@localhost opt]# chmod  777  abc    #授予abc權(quán)限
[root@localhost opt]# ll
total 0
drwxrwxrwx. 2 root root 6 Jun  5 13:18 abc
[root@localhost opt]# su - tdm    #切換用戶
Last login: Mon Jun  5 13:15:58 CST 2023 on pts/0
[tdm@localhost ~]$ cd  /opt/abc
[tdm@localhost abc]$ touch  test.txt    #創(chuàng)建test文件
[tdm@localhost abc]$ ll
total 0
-rw-rw-r--. 1 tdm tdm 0 Jun  5 13:18 test.txt    #查看文件的屬主屬組,都是tdm
[root@localhost opt]# exit    #退出tdm賬戶
logout
[root@localhost opt]# chmod g+s abc/    #給目錄abc授予sgid權(quán)限
[root@localhost opt]# ll
total 0
drwxrwsrwx. 2 root root 22 Jun  5 13:18 abc    #目錄具有sgid權(quán)限
[root@localhost opt]# su  tdm
[tdm@localhost opt]$ ll
total 0
drwxrwsrwx. 2 root root 22 Jun  5 13:18 abc
[tdm@localhost opt]$ cd abc
[tdm@localhost abc]$ touch test1.txt    #創(chuàng)建test1.txt文件
[tdm@localhost abc]$ ll
total 0
-rw-rw-r--. 1 tdm root 0 Jun  5 13:21 test1.txt    #該文件的屬組跟隨目錄的屬組是root
-rw-rw-r--. 1 tdm tdm  0 Jun  5 13:18 test.txt

2.授權(quán)、撤銷sgid權(quán)限

  • 授權(quán)格式:chmod g+s 文件名稱
  • 撤銷格式:chmod g-s 文件名稱

四.sbit

1.sticky bit 詳解

  • 如果屬主權(quán)限位上有x,則會顯示小t
  • 如果屬主權(quán)限位上沒有x,則會顯示大T

只作用在目錄上,當(dāng)一個目錄沒有設(shè)置sticky bit權(quán)限時,并且該目錄對所有的用戶都有讀寫執(zhí)行權(quán)限時,普通用戶在該目錄下創(chuàng)建的文件或目錄都會被其他用戶刪除

[root@localhost opt]# ll
total 0
drwxrwxrwx. 2 root root 6 Jun  5 13:30 abc    #當(dāng)前目錄對所有用戶都有讀寫執(zhí)行權(quán)限
[root@localhost opt]# su test    #切換至test賬戶
[test@localhost opt]$ ll
total 0
drwxrwsrwx. 2 root root 39 Jun  5 13:21 abc
[test@localhost opt]$ cd abc
[test@localhost abc]$ ll
total 0
-rw-rw-r--. 1 tdm root 0 Jun  5 13:21 test1.txt
-rw-rw-r--. 1 tdm tdm  0 Jun  5 13:18 test.txt
[test@localhost abc]$ rm -f test1.txt     #刪除test1文件
[test@localhost abc]$ rm -f test.txt     #刪除test文件
[test@localhost abc]$ ll    #目錄為空,文件已被刪除
total 0

當(dāng)一個目錄設(shè)置了sticky bit權(quán)限時,普通用戶在該目錄下所創(chuàng)建的文件或目錄,只能被該文件或目錄的屬主用戶或者root刪除,其他用戶無法刪除彼得用戶所創(chuàng)建的文件或者目錄

drwxrwxrwx. 2 root root 6 Jun  5 13:30 abc
[root@localhost opt]# chmod o+t abc    #給目錄授予sbit權(quán)限
[root@localhost opt]# ll
total 0
drwxrwxrwt. 2 root root 6 Jun  5 13:30 abc
[root@localhost opt]# su test    #切換test賬戶
[test@localhost opt]$ cd abc
[test@localhost abc]$ touch test.txt    #創(chuàng)建文件
[test@localhost abc]$ ll
total 0
-rw-rw-r--. 1 test test 0 Jun  5 13:47 test.txt
[test@localhost abc]$ exit
exit
[root@localhost opt]# su tdm    #切換tdm賬戶
[tdm@localhost opt]$ cd abc
[tdm@localhost abc]$ ll
total 0
-rw-rw-r--. 1 test test 0 Jun  5 13:47 test.txt
[tdm@localhost abc]$ rm -f  test.txt     #tdm賬戶刪除test文件
rm: cannot remove ‘test.txt': Operation not permitted    #操作不允許

2.授權(quán)、撤銷sbit權(quán)限

  • 授權(quán)格式:chmod o+t 文件名稱
  • 撤銷格式:chmod o-t 文件名稱

五.總結(jié)

  • SUID: user - 占據(jù)屬主的執(zhí)行權(quán)限位
  • s: 屬主擁有 x 權(quán)限
  • S:屬主沒有 x 權(quán)限
  • SGID: group - 占據(jù) group 的執(zhí)行權(quán)限位
  • s: group 擁有 x 權(quán)限
  • S:group 沒有 x 權(quán)限
  • Sticky: other - 占據(jù) ohter 的執(zhí)行權(quán)限位
  • t: other 擁有 x 權(quán)限
  • T:other 沒有 x 權(quán)限
類別suidsgidsbit
字符表示SST
出現(xiàn)位置用戶權(quán)限位x用戶組權(quán)限位x其他用戶權(quán)限位x
基本權(quán)限位sst
數(shù)字表示法421
八進(jìn)制表示法400020001000
生效對象用戶位用戶組其他用戶

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • ubuntu/deepin制作快捷啟動圖標(biāo)的方法

    ubuntu/deepin制作快捷啟動圖標(biāo)的方法

    這篇文章主要介紹了ubuntu/deepin制作快捷啟動圖標(biāo)的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • 阿里云服務(wù)器yum源更新問題從何而來

    阿里云服務(wù)器yum源更新問題從何而來

    阿里云服務(wù)器yum源的更新問題,問題從何而來的呢?下面通過本文給大家介紹阿里云服務(wù)器yum源更新問題,一起看看吧
    2016-05-05
  • apache服務(wù)器一個ip(如:127.0.0.1)和多個域名(虛擬主機(jī))的綁定

    apache服務(wù)器一個ip(如:127.0.0.1)和多個域名(虛擬主機(jī))的綁定

    今天在學(xué)習(xí)PHP時,用的是apache服務(wù)器有這樣的一個需求:一個ip(如:127.0.0.1)和多個域名(虛擬主機(jī))綁定,以下是我的解決方案,需要的朋友可以參考下
    2015-01-01
  • 詳解CentOS 7 網(wǎng)卡命名修改為eth0格式

    詳解CentOS 7 網(wǎng)卡命名修改為eth0格式

    這篇文章主要介紹了詳解CentOS 7 網(wǎng)卡命名修改為eth0格式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • Linux中文件/文件夾無法刪除的解決方案

    Linux中文件/文件夾無法刪除的解決方案

    這篇文章主要給大家介紹了關(guān)于Linux中文件/文件夾無法刪除的解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Linux如何運(yùn)行SQL文件

    Linux如何運(yùn)行SQL文件

    這篇文章主要介紹了Linux如何運(yùn)行SQL文件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • 最新評論