sudo uses the environment variables temporarily set by the current user (sudo -E)

1、sudo -E

-EThe options are explained in the man page:

-E

The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.

Simply put, after adding -Ethe option, the user can retain the existing environment variables of the current user when sudo is executed, and will not be reset by sudo. In addition, if the user does not have permission for the specified environment variable, an error will be reported.

For security reasons, using sudo to execute commands will be executed in a minimized environment, and the environment variables will be reset to the default state. So the PATH variable does not include the content of user-defined settings

Knowing the effect, let's take a look at the solution:

 edit /etc/sudoers

 Increase the NOPASSWD of the original default abc1234 user to SETENV:

At this time, execute sudo -E to run directly

Guess you like

Origin blog.csdn.net/leonnew/article/details/124016515