Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

To ensure the proper PATH environment variable is setup, I am using the sudo -i options, but am finding that the sudoers file isn't being respected.

Here is my setup:

/etc/sudoers:

Defaults    env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
user    ALL=(ALL) ALL
user    ALL=NOPASSWD: /usr/local/bin/chef-solo

Running sudo chef-solo -v doesn't prompt for a password. Running sudo -i chef-solo -v will prompt for a password.

share|improve this question
    
What happens when you specify the full path: sudo -i /usr/local/bin/chef-solo -v –  Mark Wagner Feb 12 '13 at 20:16
    
@MarkWagner it still asks for a password. Remove the -i and it goes through fine. –  tjwallace Feb 12 '13 at 20:19
add comment

2 Answers

up vote 4 down vote accepted

sudo -i executes your shell, not the command. It passes the command to the shell.

share|improve this answer
    
More specifically, executes a shell as the targeted user. (No -u assumes root.) Either way, this sudoers file isn't granting this privileges with NOPASSWD. –  Aaron Copley Feb 12 '13 at 20:40
    
Adding user ALL=NOPASSWD: /bin/bash worked like a charm: no password prompt. –  tjwallace Feb 12 '13 at 23:28
add comment

For sudo -i to work without a password, the rule using the alias ALL as the command to run needs the NOPASSWD flag.

At my current place of employment, policy prohibits this from being used for any command which may run as root (including su). Rather, we use NOPASSWD in conjunction with the non-root run-as user to switch accounts without using su, as in the following rule:

%group ALL=(user) NOPASSWD: ALL

This then permits the use of both "sudo -iu user" and "sudo -u user command and args".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.