在嵌入式或 Live CD 環境中切換 root 時,常會碰到這行錯誤:
su: must be suid to work properly
本文的環境是 CDLinux,核心版本 2.6.33-cdl,使用者環境為 BusyBox v1.15.3。
su 要能切換身分,必須具備 SUID 位元,讓它在執行時暫時擁有檔案擁有者(通常是 root)的權限。Live CD 在製作或解壓的過程中常會遺失這個特殊權限位元,於是 su 雖然存在,卻沒有足夠權限完成切換。
chmod 4755 busybox
實務上你會遇到第二個問題:busybox 不在目前目錄,而且一般使用者無權修改。
$ chmod 4755 busybox chmod: busybox: No such file or directory $ cd / $ sudo find -name busybox ./.cdl/initrd/bin/busybox ./bin/busybox $ chmod 4755 ./bin/busybox chmod: ./bin/busybox: Operation not permitted $ sudo chmod 4755 ./bin/busybox
加上 sudo 之後再執行 su 就正常了。
CDLinux 的 root 帳號多半沒有設定密碼,因此也可以直接:
sudo su
繞過 su 的 SUID 檢查。要理解這裡的邏輯:BusyBox 是 multi-call binary,su 只是它的一個 applet,因此修的是 /bin/busybox 的權限,而不是找一個名為 su 的檔案。權限數字 4 開頭代表 SUID,755 則是擁有者可讀寫執行、其他人可讀取執行。
同樣的問題也會出現在其他把 BusyBox 當 init 的嵌入式系統上,處理方式一模一樣。