I'm logged in as user1
and I have two scripts, script1 attempts to call script2 using sudo -u user2
. My problem is that I'm still prompted to enter password for user1
although I'm specifying -u
option for sudo
. Here is my setup:
Script1:
#! /bin/bash echo "Current user in script1:" $USER # Call script2 sudo -u user2 /full/path/to/script2
Script2:
#! /bin/bash echo "Current user in script2:" $USER # Execute command as user2 some-command-that-works
Equivalent
/etc/sudoers
to the one I have:# /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # See the man page for details on how to write a sudoers file. # Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification user1 ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command # (Note that later entries override this, so you might need to move # it further down) %sudo ALL=(ALL) ALL # #includedir /etc/sudoers.d # Don't ask for user2 password for script2 user2 ALL= NOPASSWD: /full/path/to/script2 # FYI: I experimented with the line below for group1 that user1 is a member of %group1 ALL= NOPASSWD: /full/path/to/script2
ls -blah
outputdrwxrwsr-x 2 user1 group1 4.0K Oct 19 15:22 . drwxrwsr-x 7 user1 group1 4.0K Oct 18 18:48 .. -rwxrwxr-x 1 user1 group1 180 Oct 20 17:37 script1 -rwx------ 1 user2 group1 166 Oct 20 16:29 script2
An example of my shell attempt to run script1
:
user1@host1 /full/path/to/script1 $ script1
Current user in script1: user1
[sudo] password for user1:
Edit: This is on a server that I connect to with ssh
. The server is running Debian 6.0.4 Squeeze
user1 ALL=(ALL:ALL) ALL
allows user1 to run any command as any user - including root.