sudo 指令是可以讓一般用戶以 root 身份執行指令的工具, 以下會示範在 Ubuntu 建立一個新帳號, 在不修改 sudoers 的情況下, 可以使用 sudo 以 root 身份執行指令。
建立新帳號
先用 adduser 建立新帳號:
# adduser username
設定新帳號密碼:
Set password prompts:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
接著設定新帳號資訊, 如果沒有特別需要, 一般按 “Enter” 用預設值即可, 到最後按 “Y” 後按 “Enter”:
User information prompts:
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Ubuntu 預設給 sudo 群組的帳號執行 sudo 的權限, 用 usermod 將新帳號加入 sudo 群組:
# usermod -aG sudo username
然後新建立的帳號就可以用 sudo 以 root 身份執行指令了。