Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
do you need to check wether the user has the possibility to use sudo, or if he is executing the shell script via sudo? –  Niko S P Feb 28 '12 at 4:51
    
Just whether he has the possibility. The local script will require the sudo password to be entered later on, so I just want to check early on that the user on the remote host is even a sudoer. –  DanH Feb 28 '12 at 9:32
    
a quick check on my ubuntu box gave me sudo -l, it returns the commands the user may run, if (ALL) ALL is part of them, the user is able to use sudo for any command. Maybe that's the right angle? –  Niko S P Feb 28 '12 at 11:16
    
sudo -l prompts me for my password. –  ThatGraemeGuy Feb 28 '12 at 11:55
1  
Sudo caches based on tty so a if a new session gives you the same tty you may not be prompted. Try executing sudo -k first. –  Mark Wagner Mar 6 '12 at 20:39
show 1 more comment

1 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

share|improve this answer
    
Note that this does not help preliminary detecting if command X is sudoable without entering a password and without accidently running it –  try-catch-finally Jul 2 at 23:05
add comment

Your Answer

 
discard

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.