There are two Python interpreters installed:[user@localhost ~]$ /usr/bin/python -V && /usr/local/bin/python -VPython 2.4.3Python 2.7.6Sudo changes PATH when executed:[user@localhost ~]$ env | grep PATH && sudo env | grep PATHPATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/user/binPATH=/usr/bin:/binYet Python run through sudo is the same as the one run directly:[user@localhost ~]$ sudo python -V && python -VPython 2.7.6Python 2.7.6I would expect sudo python to run /usr/bin/python which is the only one visible on the modified PATH.Why does it run /usr/local/bin/python instead?I asked this question on sudo-users mailing list but we couldn't find the reason for this behavior in discussion with sudo maintainer Todd C. Miller.For reference:[user@localhost ~]$ sudo -lMatching Defaults entries for user on this host:    requiretty, !visiblepw, env_reset, env_keep=COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS    LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE    LINGUAS _XKB_CHARSET XAUTHORITYRunas and Command-specific defaults for user:User user may run the following commands on this host:    (ALL) NOPASSWD: ALL[user@localhost ~]$ sudo sudo -VSudo version 1.7.2p1Sudoers path: /etc/sudoersnsswitch path: /etc/nsswitch.confldap.conf path: /etc/ldap.confldap.secret path: /etc/ldap.secretAuthentication methods: 'pam'Syslog facility if syslog is being used for logging: authprivSyslog priority to use when user authenticates successfully: noticeSyslog priority to use when user authenticates unsuccessfully: alertIgnore '.' in $PATHSend mail if the user is not in sudoersUse a separate timestamp for each user/tty comboLecture user the first time they run sudoRequire users to authenticate by defaultRoot may run sudoAllow some information gathering to give useful error messagesVisudo will honor the EDITOR environment variableSet the LOGNAME and USER environment variablesLength at which to wrap log file lines (0 for no wrap): 80Authentication timestamp timeout: 5 minutesPassword prompt timeout: 5 minutesNumber of tries to enter a password: 3Umask to use or 0777 to use user's: 022Path to mail program: /usr/sbin/sendmailFlags for mail program: -tAddress to send mail to: rootSubject line for mail messages: *** SECURITY information for %h ***Incorrect password message: Sorry, try again.Path to authentication timestamp dir: /var/run/sudoDefault password prompt: [sudo] password for %p: Default user to run commands as: rootPath to the editor for use by visudo: /bin/viWhen to require a password for 'list' pseudocommand: anyWhen to require a password for 'verify' pseudocommand: allFile containing dummy exec functions: /usr/libexec/sudo_noexec.soFile descriptors >= 3 will be closed before executing a commandReset the environment to a default set of variablesEnvironment variables to check for sanity:        TERM        LINGUAS        LC_*        LANGUAGE        LANG        COLORTERMEnvironment variables to remove:        RUBYOPT        RUBYLIB        PYTHONINSPECT        PYTHONPATH        PYTHONHOME        TMPPREFIX        ZDOTDIR        READNULLCMD        NULLCMD        FPATH        PERL5DB        PERL5OPT        PERL5LIB        PERLLIB        PERLIO_DEBUG         JAVA_TOOL_OPTIONS        SHELLOPTS        GLOBIGNORE        PS4        BASH_ENV        ENV        TERMCAP        TERMPATH        TERMINFO_DIRS        TERMINFO        _RLD*        LD_*        PATH_LOCALE        NLSPATH        HOSTALIASES        RES_OPTIONS        LOCALDOMAIN        CDPATH        IFSEnvironment variables to preserve:        XAUTHORIZATION        XAUTHORITY        TZ        PS2        PS1        PATH        MAIL        LS_COLORS        KRB5CCNAME        HOSTNAME        HOME        DISPLAY        COLORSLocale to use while parsing sudoers: CLocal IP address and netmask pairs:        10.0.2.15 / 255.255.255.0        fe80::a00:27ff:febb:56ce / ffff:ffff:ffff:ffff::[user@localhost ~]$ sudo cat /etc/sudoers | grep -v -E '^#|^$'Defaults    requirettyDefaults   !visiblepwDefaults    env_resetDefaults    env_keep = COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \                        LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \                        LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \                        LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \                        LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \                        _XKB_CHARSET XAUTHORITYroot    ALL=(ALL)       ALLuser    ALL=(ALL)       NOPASSWD: ALL[user@localhost ~]$ which sudo && command -V sudo/usr/bin/sudosudo is hashed (/usr/bin/sudo)[user@localhost ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.10 (Tikanga)
Sudo changes PATH, yet executes the same binary
sudo;path
You are getting confused between the PATH which is in the actual sudo execution environment and the PATH which sudo sets in the environment of the program which it runs. From the sudo manual:When sudo runs a command, it calls fork(2), sets up the execution environment as described above, and calls the execve system call in the child process.With execve you specify the environment that you want the child process to have, ie it can be different from the parent process.Often secure_path will be set in /etc/sudoers:secure_pathPath used for every command run from sudo.  If you don't trust the people running sudo to have a sane PATH environment variable you may want to use this.  Another use                     is if you want to have the root path be separate from the user path.  Users in the group specified by the exempt_group option are not affected by secure_path.                     This option is not set by default.If this is set, sudo will both search for the command in this PATH and set this in the environment of the command it runs. It will also show up in the output of sudo sudo -V with a line like:Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHowever in your case this is not set, so sudo will use the PATH in its own execution environment (which in this case is inherited from the parent shell). Although it has been configured to ignore the current directory if this has been put in the PATH:Ignore '.' in $PATHSince env_reset is in your /etc/sudoers (and PATH is not in the env_keep string), the PATH that sudo sets in the command it calls will be defined by PAM or by /etc/environment and is thus different from the PATH sudo uses to search for its location:By default, the env_reset option is enabled.  This causes commands to be executed with a new, minimal environment.  On AIX (and Linux systems without PAM), the environment is initialized with the contents of the /etc/environment file.  The new environment contains the TERM, PATH, HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables in addition       to variables from the invoking process permitted by the env_check and env_keep options.To run the python in the PATH set by sudo, you should do something like this:sudo env python -VThis way it is not sudo itself which is searching for the command, rather env will have the environment set by sudo and env will search for the command there.