Mailinglist Archive: opensuse (946 mails)

< Previous Next >
Re: [opensuse] Run command as another user
28.09.2017 17:34, Paul Groves пишет:

I need to be able to run a command as another user.

I have worked out that I can run the following from one user to execute
a command as the other (bob).

su - bob -c command
prompt for password
enter password

command runs as bob

but, how can I run this on one line for use in a script? (so that I am
not prompted for a password).
something like; su - bob -c command -p bobspassword

The user executing the script is not a sudoer so I cannot use; echo
bobspassword | sudo -S -u bob command

Well ... the only thing you can do is without having superuser rights
for this system is to compile SUID binary owned by user bob that
executes needed command. I presume making command SUID directly is not
an option.

And if you do have superuser rights, you can simply edit sudoers and let
user run this script as bob (even without password).

Keep in mind that if your "command" is a script, shell does not like
being run suid and so will likely reset EUID back to calling user ...
unless you use sudo which makes sure it does not happen.

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
List Navigation
Follow Ups