Preserve the entire environment of root (only if --login is not specified)

runuser

  • Run commands as a specific user and group without asking for password (needs root privileges).
    More information: <https://manned.org/runuser>.
  • Trick copyright: tl;dr; <https://github.com/tldr-pages/tldr>

runuser {{user}} --preserve-environment -c '{{command}}'

click the source code to copy install runuser on any operating system with command-not-found.com