Your configuration is a little abnormal. Normally you would add your username to sudoers, and limit the applications that can be executed in this manner if required. Without knowing more detail, I can't see any benefit to introducing a third account. It just introduces more indirection, which is what you're encountering now.
The first password you enter is to become the sudo-user. You can't avoid this - you're switching users. Here are some crazy workarounds that come to mind which you shouldn't use.
- You could set an empty password for the user to make login simpler, but that would be an insane security risk. Do not do this.
- You could automate the login with
expect
and a hardcoded password. This is no more secure than the previous suggestion. Do not do this.
- You could use ssh. You'd create a ssh key as the sudo-user, copy it to your user's .ssh dir, permission it for your user, append it to the sudouser's .ssh/authorized_keys, and then use:
ssh -i .ssh/sudouser_id_rsa sudouser@localhost <command>
. It may work, but it's crazy.
The second password can easily be removed by editing the sudoers file with visudo
and setting the sudouser as NOPASSWD. This is a more common operation. You can even limit the commands which don't require a password, which is obviously recommended if you only intend to run a few commands in this manner. Note, however, that unless this sudo user is treated very seriously, having a NOPASSWD policy is not a good idea. Generally speaking, it isn't a good idea regardless.
A configuration which can run all commands without a password prompt would look like:
sudouser ALL= NOPASSWD: ALL
Bottom line - I don't see why you're using this three account configuration. Setting that to one side, in terms of giving you what you asked for, allowing the sudo user to run certain commands without being prompted for a password is the most sensible route.
You have to be careful though - that creates a less secure setup.
As an aside, it is technically possible to achieve a zero authentication solution within your guidelines, by using both ssh key-based authentication and NOPASSWD for the sudo user, so your commands would look like:
ssh -i .ssh/sudouser_id_rsa sudouser@localhost sudo whatever_i_like
That's obviously way beyond insecure - that's just plain open. I shouldn't need to say it, but don't do that.