Run an executable as different user in linux without knowing the password
There's an executable that's usually run by user A and writers in a directory only readable, writable, etc. by user A. Is it possible to allow user B in the same group to run the executable as user A so that it writes in the same directories, etc., without user B knowing the password of user A and without having access to root (i.e. cannot use visudo)?
Yes, this can be done using chmod u+s
to setuid the executable to run with the effective ID of the owner of the executable. More here and here.
Setting up sudo
to allow B to execute a particular command as A would probably be the best and safest approach, but you said you can't use visudo
.
Assuming your system has a working ssh server, you could add B's public key to /home/A/.ssh/authorized_keys
. B could then run:
ssh A@localhost some_command
without having to know A's password.
The trouble is that this gives B full access to A's account. It's not quite as bad as giving B A's password.
There may be ways to set up ssh to permit B to run only certain commands, but I don't know what they are.
(chmod u+s
, as Nicole's answer suggests, is probably cleaner; I should have thought of it.)