Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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
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

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

Your Answer


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.