Sudo

Revision as of 11:12, 8 October 2025 by Ardenet (talk | contribs) (Created page with "[https://www.sudo.ws Sudo] 允许系统管理员委托权限,授予某些用户(或用户组)以 root 或其他用户身份运行命令的能力,同时提供命令及其参数的审计跟踪。")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Sudo 允许系统管理员委托权限,授予某些用户(或用户组)以 root 或其他用户身份运行命令的能力,同时提供命令及其参数的审计跟踪。

Usage

Enable sudo-usage for the example user myuser.
users.users.myuser.extraGroups = [ "wheel" ];

Following simple configuration will allow all users which are part of the group wheel to execute commands specified inside extraRules as super user using sudo without the need to supply a user password.

security.sudo = {
  enable = true;
  extraRules = [{
    commands = [
      {
        command = "${pkgs.systemd}/bin/systemctl suspend";
        options = [ "NOPASSWD" ];
      }
      {
        command = "${pkgs.systemd}/bin/reboot";
        options = [ "NOPASSWD" ];
      }
      {
        command = "${pkgs.systemd}/bin/poweroff";
        options = [ "NOPASSWD" ];
      }
    ];
    groups = [ "wheel" ];
  }];
  extraConfig = with pkgs; ''
    Defaults:picloud secure_path="${lib.makeBinPath [
      systemd
    ]}:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin"
  '';
};