Mailinglist Archive: opensuse (936 mails)

< Previous Next >
Re: [opensuse] Run command as another user
28.09.2017 20:16, Simon Heimbach пишет:
Hi Paul,


I see two ways of getting around the password

1) Use spawn/expect/send
Have a look here:
https://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash


Of course, thanks for the reminder, expect is swiss army knife if one
needs to provide "terminal" input to a program. BTW, zsh has module that
implements pty, created for similar purpose (it allows starting program
connected to a "terminal" and supply input to it).

2) Create a sudo-exception:
Have a look here:
https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html

Anyway, be careful about both! Think twice about your security!


Simon

Am 28.09.2017 um 16:34 schrieb Paul Groves:
Hi,

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

thanks
Paul




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

< Previous Next >
List Navigation