在/etc/sudoers我看到的是:
# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
那么如何将用户添加到该sudo组?
在/etc/sudoers我看到的是:
# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
那么如何将用户添加到该sudo组?
Answers:
sudo usermod -aG sudo <username>
这a非常重要。没有它,它们将从所有其他组中删除。您将需要重新启动外壳程序/终端或注销然后重新登录才能生效。
也可以看看:
bash: sudo: command not found,为什么?
sudo安装,或者由于某些奇怪的原因,它不在您的路径中。跑步时会发生什么which sudo?
a是附加的,但我认为将附加作为默认行为会更有用。创建别名很容易,因此可以将其groupadd group追加。我今天不带-a命令执行一次,因为我不记得该-a参数了。
sudo usermod -aG sudo <username>。因为没有找到我的简便方法。
您可以为其使用用户管理GUI(在同一位置创建用户),也可以sudo adduser <username> sudo在命令行中使用。
Usage: adduser [options] LOGIN\n adduser -D\n adduser -D [options]\n
如果您将Unity用作桌面环境,这真的很简单。
如果已经创建了一个用户,则可以将其从Standard更改为Administrator,否则请确保在创建新用户时选择了Administrator。
在尝试更改之前不要忘记解锁

我参加聚会很晚,但是这个答案可能会对在Docker容器中使用Ubuntu的人有所帮助。
我最近创建了一个基于Ubuntu 16.04.1。的Docker容器。
默认情况下,Docker Ubuntu映像是Ubuntu的精简版,它没有包括在内的绝大多数常用工具sudo。
此外,默认情况下,用户以root用户身份登录到Docker容器。
因此,我使用docker run命令启动了容器,并安装了'sudo'软件包:
root@default:/# apt-get install sudo
运行命令adduser myuser sudo报告错误adduser: The user 'myuser' does not exist.。阅读此答案后,我首先运行命令来创建用户:
root@default:/# adduser myuser
然后运行以下命令:
root@default:/# adduser myuser sudo
Adding user `myuser' to group `sudo' ...
Adding user myuser to group sudo
Done.
用户myuser已成功添加到sudo组。
这是我使用以下基本映像设置非root用户的方法ubuntu:18.04:
RUN \
groupadd -g 999 foo && useradd -u 999 -g foo -G sudo -m -s /bin/bash foo && \
sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g' && \
sed -i /etc/sudoers -re 's/^root.*/root ALL=(ALL:ALL) NOPASSWD: ALL/g' && \
sed -i /etc/sudoers -re 's/^#includedir.*/## **Removed the include directive** ##"/g' && \
echo "foo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
echo "Customized the sudoers file for passwordless access to the foo user!" && \
echo "foo user:"; su - foo -c id
上面的代码会发生什么:
foo已创建。foo被添加到foo和sudo组中。uid和gid被设置为值999。/home/foo。/bin/bash。sed命令对/etc/sudoers文件进行内联更新以允许foo和root用户无密码访问该sudo组。sed命令禁用#includedir指令,该指令将允许子目录中的任何文件覆盖这些内联更新。