Problem executing command as a different user with sudo -u
You should configure sudo security policy to allow user xyz exec something as user abc. Read 'man sudoers' and use visudo command to configure /etc/sudoers.
For example let's allow user xyz exec /usr/bin/whoami as user abc without password. Add this string into /etc/sudoers (with visudo, don't edit /etc/sudoers directly):
xyz ALL = (abc) NOPASSWD: /usr/bin/whoami
And now test it:
xyz@host:~$ sudo -u abc /usr/bin/whoami
abc
This is because sudo
is different from su
. When you su abc
, you become the user abc
as far as the system is concerned. You can then do anything that abc
can do.
On the other hand, sudo
is used to allow other users to execute some commands by proxy. In other words, your sudo
configuration allows you to do some commands on behalf of abc
. If the command you're trying to execute is not one of them, you get the error you reported.