# Security - root password entered with every command

**URL:** https://discourse.nixosstag.fcio.net/t/security-root-password-entered-with-every-command/64362
**Category:** Guides
**Created:** [May 17, 2025, 2:39am UTC](https://discourse.nixosstag.fcio.net/t/security-root-password-entered-with-every-command/64362 "2025-05-17T02:39:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![milomak](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/milomak/32/32399_2.png) [@milomak](https://discourse.nixosstag.fcio.net/u/milomak)
#### Post date: [May 17, 2025, 2:39am UTC](https://discourse.nixosstag.fcio.net/t/security-root-password-entered-with-every-command/64362/1 "2025-05-17T02:39:18Z")

</div>

i found that i wanted to know how i could have sudo ask for the root password everytime

i eventually found it

```auto
{ config, pkgs, ... }:

{
  security.sudo = {
    enable = true;
    wheelNeedsPassword = true; # Require password for sudo (default: user's password)
    configFile = ''
      # Force root password instead of user password
      Defaults rootpw
      # Disable sudo timeout (ask for password every time)
      Defaults timestamp_timeout=0
    '';
  };
}

```

---

<div class="post-metadata">

### Author: ![milomak](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/milomak/32/32399_2.png) [@milomak](https://discourse.nixosstag.fcio.net/u/milomak)
#### Post date: [May 17, 2025, 2:40am UTC](https://discourse.nixosstag.fcio.net/t/security-root-password-entered-with-every-command/64362/2 "2025-05-17T02:40:57Z")

</div>

i have this as /etc/nixos/file.nix

i then have it inculed in /etc/nix/configuration.nix

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/tlater/32/4257_2.png) [@TLATER](https://discourse.nixosstag.fcio.net/u/TLATER)
#### Post date: [May 17, 2025, 5:27am UTC](https://discourse.nixosstag.fcio.net/t/security-root-password-entered-with-every-command/64362/3 "2025-05-17T05:27:10Z")

</div>

> [@milomak](#):
>
> ```auto
> # Force root password instead of user password
> Defaults rootpw
> 
> ```

This is probably fine on a system where the only user is the administrator, but it should not be done in general. This means that any user who is given permission to do anything with `sudo` must also be able to log in as root; you have no finer control over which user can do what anymore.

You don’t get any additional security of any kind, either, only users added to the `wheel` group can use `sudo` anyway, you don’t need to authorize them again, just authenticate; this is why the default is the user password. This setting probably only exists so that `sudo` can replace homebrew hacky scripts from 45 years ago, don’t use it on a modern system. Don’t even use it on a 40 year old system.

On a side note, I don’t think the root user should even _have_ a password - logging in as root is always a terrible idea, use `sudo -s` if you need a root shell.
