Posted on

給予使用者帳號sudo權限

創建使用者帳號

  • 使用有root權限的使用者登入系統
  • 使用useradd來創建一個普通的使用者帳號
    # useradd USERNAME
  • 設定這個使用者的密碼
    # passwd USERNAME
    Changing password for user USERNAME.
    New password:
    Retype new password:
    passwd: all authentication tokens updated successfully.
  • 使用visudo去編輯/etc/sudoers檔案
    # visudo
  • 尋找下面這行代表擁有sudo權限的群組的設定,並移除前面的#字號
    ## Allows people in group wheel to run all commands
    # %wheel ALL=(ALL) ALL
  • 新增剛剛創建的使用者進入剛剛的群組裡
    # usermod -aG wheel USERNAME

測試是否有成功給予權限

  • 轉換身份至剛剛創建的帳號
    # su USERNAME -
  • 查看所在群組
    $ groups
    USERNAME wheel
  • 測試sudo指令
    $ sudo whoami
    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.

    [sudo] password for USERNAME:
    root

參考資料