On a machine I (tlous) have been given access to open a shell as another user (serviceAccount)
sudo su - serviceAccount has the desired effect of opening a shell as this serviceAccount user. So far so good.
This is nice, but I want to run a command as this user without opening a shell.
Let's say the command is
sudo -u serviceAccount whoami
Sorry, user tlous is not allowed to execute '/usr/bin/whoami' as serviceAccount ...
sudo su - serviceAccount -c whoami
Sorry, user tlous is not allowed to execute
'/bin/su - serviceAccount -c whoami' ...
And other variations. What am I missing? Can this be done in a oneliner? The reason is that I actually want to run this as an ssh command:
ssh -t [email protected] sudo su - serviceAccount -c whoami
Update 20190412 with sudo -l
Matching Defaults entries for tlous on this host: !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin, !authenticate User tlous may run the following commands on this host: (root) /usr/bin/su - serviceAccount, /bin/su - serviceAccount