Search code examples
commandsudosudoers

sudo -l for a different as root


Hi all am trying list all the sudo command a user has access to as a root , obviously we can see that in sudoers file but if there are a lot of user/command aliases it becomes difficult

i am trying to do sudo -l for a different user as root

i have tried using -u option

sudo -u testuser -l 

throws command usage message

sudo -u testuser sudo -l

prompts for testuser's password (i dont want password prompt as i am doing as root)

su - testuser -c 'sudo -l' 

gives me below error

sudo: no tty present and no askpass program specified

please let me know how to go about this


Solution

  • As per man sudo:

     -U user, --other-user=user
                 Used in conjunction with the -l option to list the privileges
                 for user instead of for the invoking user.  The security pol-
                 icy may restrict listing other users' privileges.  The
                 sudoers policy only allows root or a user with the ALL privi-
                 lege on the current host to use this option.
    

    you're using -u, which is something completely different:

     -u user, --user=user
                 Run the command as a user other than the default target user
                 (usually root ). The user may be either a user name or a
                 numeric user ID (UID) prefixed with the '#' character etc...