Is there a non-interactive (unattended, not requiring a ncurses-based control terminal) method to verify that sudo is configured properly to allow passwordless sudo'ing from one non-root user account to another?
I have a scenario where some processing needs to execute on a different user account, but the execution needs to occur without any user intervention since there will not be a control terminal available (e.g., from a background process).
This is running under Linux (specifically RHEL 5 or RHEL 6, or the rough equivalent CentOS machines). No other operating systems, or Linux variants, are relevant for this question.
For sake of discussion, assume there are two user accounts involved: userA and userB.
I need a method to verify that it is possible to do a passwordless sudo from userA to userB, all from the userB account.
The commands being executed in the userB account inside that sudo call will be for things such as running user-space programs (e.g., not running system administration commands such as
The key constraint here is that the method should be able to be done from the userB account, not the userA account, in a background process without a control terminal.
That method should be possible to implement in a Bash script by using sed/awk/etc. commands to inspect files.
The system administrator should not have to be involved for this method (e.g., no setuid scripts required).
Is that possible? If so, how?
Consider that the sudoers file may be difficult to parse. Looking at a similar question in How to run a specific program as root without a password prompt? it is not clear how a non-root script can inspect the contents of the sudoers file without using some interactive mechanism such as
visudo which will require a ncurses enabled terminal which is not an option.
Also https://unix.stackexchange.com/a/260739/21372 indicates the proper syntax for passwordless sudo from userA to userB, but my question here probably just boils down to how to see that configuration without running a ncurses-constrained application such as
visudo, but I'm not sure it is that simple.