[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Need help running command as another user using su



Hi,

TLDR: is it possible to run a command as another user using su, if
that user is a system user?


I'm trying to solve bug#739637 by running the command as user
gnuhealth, using the command `su` instead of `sudo`.

Let's take a simple example to start, running the command whoami as
another user, from a root shell.

First, become root by your prefered way (I use sudo ;) )
emilien@debiansid:~$ sudo su -
[sudo] password for emilien:
root@debiansid:~#

Running the command using sudo, I see the username being returned as expected:

root@debiansid:~# sudo -u gnuhealth whoami
gnuhealth


Now trying to reproduce that using su.
According to the manpage:
su [options] [username]
-c, --command COMMAND

So I would expect to first have the command name su, then -c and the
command to execute, and then the username.

root@debiansid:~# su -c whoami gnuhealth
root@debiansid:~#

That doesn't return the expected output.

Trying different kinds of possibilities (quoting the command, using =
and putting the username before the command) doesn't give better
results:

root@debiansid:~# su -c "whoami" gnuhealth
root@debiansid:~# su -c=whoami gnuhealth
root@debiansid:~# su -c="whoami" gnuhealth
root@debiansid:~# su --command whoami gnuhealth
root@debiansid:~# su --command "whoami" gnuhealth
root@debiansid:~# su --command=whoami gnuhealth
root@debiansid:~# su --command="whoami" gnuhealth
root@debiansid:~# su gnuhealth -c whoami
root@debiansid:~# su gnuhealth -c "whoami"
root@debiansid:~# su gnuhealth -c=whoami
root@debiansid:~# su gnuhealth -c="whoami"
root@debiansid:~# su gnuhealth --command whoami
root@debiansid:~# su gnuhealth --command "whoami"
root@debiansid:~# su gnuhealth --command=whoami
root@debiansid:~# su gnuhealth --command="whoami"
root@debiansid:~#

The weird part is that running these commands [*] in a terminal on my
Ubuntu host machine *do* return the expected username back.
What could be the reason I don't get the command su to run on my
Debian sid machine?
Are you able to run that?


Aaaaaah, wait, now that I'm typing this, I have an enlightenment: the
user is created as a system user (I believed according to the
instructions on the GNU Health wiki, but I can't find that back now).
Could that be the reason why I can't get su to run the command as that
user?

User creation is done in gnuhealth-server.postinst by this command:
adduser --home /var/lib/gnuhealth --quiet --system --group gnuhealth


Questions:
- Is it possible to run a command as another user using su, if that
user is a system user?
- Should the created user not be a system user?

Cheers,
   +Emilien


[*] except the variants using = with -c


Reply to: