裝完系統發現 sudo 完全無法使用,只會看到一段似曾相識的長篇警告:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
查了資料後,解法如下:
su - 登入 root 模式chmod 740 /etc/sudoers
vi /etc/sudoers
root ALL=(ALL) ALL 那行下面另起一行,加上你的帳號:username ALL=(ALL) ALL
chmod 440 /etc/sudoers
若想使用 sudo 時不必輸入密碼,把第 4 步改成:
username ALL=NOPASSWD:ALL
完整的 sudoers 範例:
# /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL #tiger ALL=(ALL) ALL tiger ALL=NOPASSWD:ALL # Uncomment to allow members of group sudo to not need a password # %sudo ALL=NOPASSWD: ALL
兩個提醒:一是權限必須還原成 440,否則 sudo 基於安全考量會拒絕運作;二是官方建議用 visudo 編輯這個檔案,因為它會在存檔前做語法檢查,能避免你把自己鎖在門外。NOPASSWD 雖然方便,但等於讓任何取得該帳號的人都能直接當 root,共用機器上最好別開。