[常見問與答] sudo: effective uid is not 0, is sudo installed setuid root?

在某些情況下,sudo 會突然失靈,回傳錯誤訊息如: sudo: effective uid is not 0, is sudo installed setuid root?

解決方法如下:

1. 將 SD 卡接到其他電腦,在 /boot/cmdline.txt 最後面加上 single

2. 將 SD 卡插回 Raspberry Pi,重新啟動後將會進入 single user mode。

3. 將 /usr 的擁有者和群組改成 root,並修改全部權限為 rX 。

chown -R root:root /usr
chmod -R a+rX /usr

4. 更改 sudo 相關檔案的使用者和權限。

chown root:root /usr/lib/sudo/sudoers.so
chown -R root:root /etc/sudoers*
chmod 4755 /usr/bin/sudo

5. 測試。

su - pi
sudo
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] []
usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ...

6. 將 single user mode 取消後重開機就大功告成了。

Leave a Reply

Your email address will not be published. Required fields are marked *