Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 普通用戶無法使用 reboot/shutdown?用 SUID 權限解決

編輯:關於 Linux

普通用戶執行 reboot、shutdown 等系統指令時提示「權限不足」。透過賦予執行檔 SUID(Set User ID) 特殊權限,可讓普通用戶以檔案擁有者(root)身份執行該指令,從而繞過權限限制。

操作步驟

  1. 以 root 登入系統。
  2. 查詢指令絕對路徑:
which reboot
# /sbin/reboot
  1. 賦予 SUID 權限(數字模式 4xxx):
chmod 4744 /sbin/reboot
# 或符號模式:chmod u+s /sbin/reboot
  1. 切換至普通用戶測試:
su - user1
reboot
# 成功重啟

SUID 權限設定示意圖

原理解析

  • chmod 4744 中首位 4 代表 SUID,執行時有效 UID 變為檔案擁有者(root)。
  • 權限顯示為 -rwsr--r--(擁有者執行位變為 s)。
  • 同理可對 /sbin/shutdown、/sbin/halt、/sbin/poweroff 設定。

安全性警示

  • SUID 程式若有漏洞,可能被提權攻擊。僅對必要指令設定,並定期稽核:find / -perm -4000 -type f 2>/dev/null。
  • 生產環境建議改用 sudo 配置 /etc/sudoers(如 user1 ALL=(ALL) NOPASSWD: /sbin/reboot),可控性更高且有稽核軌跡。
Copyright © Windows教程網 All Rights Reserved