我安装并尝试开始使用 NixOS,并尝试将我的用户添加到 sudoers 文件中。
为了不以 root 身份运行所有命令,我按照 NixOS 手册的第 7 章用户管理创建了一个用户。也就是说,我跑了
# useradd -m matthew
# su - matthew -c "true"
# passwd matthew
Enter new UNIX password: ***
Retype new UNIX password: ***
Run Code Online (Sandbox Code Playgroud)
我还补充说
users.extraUsers.matthew = {
isNormalUser = true;
home = "/home/matthew";
extragroups = [ "wheel" "networkmanager" ];
}
Run Code Online (Sandbox Code Playgroud)
到/etc/nixos/configuration.nix
。但我仍无法运行sudo
的matthew
。例如,当我尝试使用 sudo 打开 sudo 的手册页时,matthew is not in the sudoers file
出现错误。
$ sudo man sudo
[sudo] password for matthew:
matthew is not in the sudoers file. This incident will be reported.
Run Code Online (Sandbox Code Playgroud)
然后我尝试以下建议如何在其他分布的用户添加到sudoers文件,即与编辑$ visudo
。但是当我运行它时,nixos 告诉我不要编辑那个文件。也就是说,运行
$ visudo
Run Code Online (Sandbox Code Playgroud)
打开/etc/sudoers.tmp
第一行阅读
# Don't edit this file. Set the NixOS option ‘security.sudo.configFile’ instead.
Run Code Online (Sandbox Code Playgroud)
如何设置 NixOS 选项“security.sudo.configFile”?
首先,添加用户useradd
并编辑 users.extraUsers 是多余的。我从来没有为useradd
NixOS烦恼过。
至于 sudo 配置,您要做的是将属性设置为一个字符串,该字符串包含您通常放入 sudoers 的内容。
...
security.sudo.configFile = ''
Sudoers config goes here
''
...
Run Code Online (Sandbox Code Playgroud)
将用户添加到wheel
组应该足以获得 sudo 权限。
users.extraUsers.matthew = {
isNormalUser = true;
home = "/home/matthew";
extragroups = [ "wheel" ];
}
Run Code Online (Sandbox Code Playgroud)
之后您将用户添加到一个新的Linux组,则需要注销和登录的用户,对于那些更改生效(新组)。
归档时间: |
|
查看次数: |
6722 次 |
最近记录: |