First give a very nice sudo document!
Https://wiki.archlinux.org/index.php/Sudo_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29
Question number one: How to use sudo to execute commands without entering the password
Execute the Visudo under root
Add at the end of the file:
myuser all= (All) Nopasswd:all
%mygroup all= (All) Nopasswd:all
Question two: If Hugh executes the command using sudo to ensure that the environment variable is passed
First, we can always use
sudo-u Targetuser EnvTo check the environment variables of the target user targetuser, especially some home directories and path variables you define
Here are two important configuration steps:
1. Ensure that environment variables are passed, for example, for some Hadoop-related environment variables, we need to add environment variables that need to be passed in Visudo, such as:
Defaults Env_keep + = "Java_home hadoop_home hbase_home hive_home mahout_home PATH"
2. The guaranteed path variable is passed:
The path variable of the Env_keep configuration above is actually not effectively passed, and the path variable is constrained by Secure_path, and if we need to pass the complete path variable, we need to modify the secure_path! In Visudo, its default value is generally:
Defaults Secure_path =/sbin:/bin:/usr/sbin:/usr/bin
Also in the case of the Hadoop environment, we can instead:
Defaults Secure_path =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_71/bin:/usr/local /hadoop/bin:/usr/local/hadoop/sbin:/usr/local/hbase/bin:/usr/local/hive/bin:/usr/local/hive/hcatalog/bin:/usr/ Local/hive/hcatalog/sbin:/usr/local/mahout/bin
Another: If you do not make the above configuration, you can use
sudo-i-u targetuser your-commandTo execute your command, use the-I parameter to simulate a login, the target user's relevant environment variables can be initialized accordingly!
sudo FAQ two: password-free/Keep environment variable