Ssh – Test whether a user has sudo privileges without requiring user input

sshsudo

I have a local shell script that performs a number of tests on a remote host, before delivering the payload; one of these tests being whether the user has sudo privileges, checked simply with sudo -v however this requires the user to enter their password. Additionally the remote host seems to have instant sudo timeout so the password entry is required on every new connection, and this is something I don't have permission to change (as a policy).

I can of course test whether the user is part of certain groups, but then this would not be agnostic to the remote host configuration, so I was hoping there's a method that can check that doesn't need to assume the user's groups, as well as not needing user input?

Thanks!

UPDATE: To echo my comments, I only want to test whether a user could possibly sudo, without requiring user interaction for that test.

Best Answer

I'm afraid the only thing you can test is if the user has sudo privileges without a password.

Execute

sudo -n true

If $? is 0, the user has sudo access without a password, if $? is 1, the user needs a password.

If you need verification for a specific program, change true with your program, in a way the program doesn't do anything, like chmod --help