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 身份执行指令了。