I need to execute a command as another user by providing THEIR password. This must be able to be done without a terminal aka purely through bash script. I also need to be able to do this without installing a custom package (sshpass, etc) or configuring any root-accessible files (sudoers, etc).
Things I have tried:
sudo -u 'myuser' -- sh -c 'mycommand'
su - 'myuser' -c 'mycommand'
ssh 'myuser'@localhost 'mycommand'
All of these work in accomplishing the goal of executing a command as another user. However, the authentication is the problem...
sudo
- Allows you to supply password through standard input using the-S
flag. However, it requests your password - not the password of the user you're trying to execute the command as.su
- Allows you to supply their password instead of yours but it can only be supplied through a terminal!ssh
- Allows you to supply their password but it also can only be supplied through a terminal. It also has much more overhead than the previous two.
If su
had a -S
flag like sudo
this problem would be solved.
Does something (built-in) exist that can perform this operation? If not, why doesn't it exist? There doesn't seem to be any issue with security because sudo
already provides the ability to pass passwords through standard input.
0 Answers