sudo FAQ two: password-free/Keep environment variable

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.