在NixOS下似乎无法使sudo工作

宗教

标题(令人尴尬)说明了一切。首先介绍一些背景信息:

我正在Vultr上使用自定义ISO运行NixOS。

尝试时间范围:

  • which sudo 没有显示sudo
  • 安装sudo使用nix-env -i sudo
  • 然后,当我想sudo ...,我看sudo: /home/agam/.nix-profile/bin/sudo must be owned by uid 0 and have the setuid bit set
  • sudo su 由于相同的原因而无法正常工作
  • 好的,我已将其卸载(nix-env --uninstall sudo
  • 以为嗯,也许我应该以root身份安装它?
  • 如此,su然后重复安装
  • 现在,当我尝试进行操作时sudo ...,我看到了sudo: /nix/var/nix/profiles/default/bin/sudo must be owned by uid 0 and have the setuid bit set(与以前相同的错误,但路径不同)
  • 作为最后的选择,请尝试使用锤子,并赞扬NixOS阻止了我:
[root@nixos:/home/agam]# chmod 4755 /nix/var/nix/profiles/default/bin/sudo
chmod: changing permissions of '/nix/var/nix/profiles/default/bin/sudo': Read-only file system

关于这里发生的事情有什么线索吗?

我在这里看到的一些可能的选择是:1. Vultr提供的自定义ISO丢失了某些内容2.sudo应该在NixOS中工作的一些根本不同的方式3.我缺少了一些非常基本的使用方法Nix(最有可能!)

一些细节:

[agam@nixos:~]$ nixos-version
18.09.1534.d45a0d7a4f5 (Jellyfish)

[agam@nixos:~]$ which sudo
/nix/var/nix/profiles/default/bin/sudo

[agam@nixos:~]$ nix-channel --list
nixos https://nixos.org/channels/nixos-18.09

编辑:有效的最后一组步骤:

  1. 根据答案中的建议,首先启用sudo:
security.sudo.enable =  true;
  1. 将sudoers部分添加到/etc/nixos/configuration.nix
  # Allow members of the "wheel" group to sudo:
  security.sudo.configFile = ''
    %wheel ALL=(ALL) ALL
  '';
  1. 将我自己添加到wheel
usermod -a -G wheel agam
罗伯特·亨辛

sudo在NixOS上安装的方法是添加到configuration.nix

security.sudo.enable = true;

Nix本身根本无法创建像sudo这样的setuid二进制文件。否则,它不能是“安全且无策略的”-没有多用户支持。nix/ nix-*工具被设计来执行安全存储操作,而不是允许特权提升。

为了支持setuid二进制文件sudo,NixOS在Nix存储区的外部维护了setuid包装器的目录/run/wrappers这仅是因为NixOS是使用root特权启动/切换/激活的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章