I'm new to working with OS and unix, I'm trying to create separate users for an application, nginx, etc... and in order to run the process on their behalf. I'm currently debugging the following ways to run the command, and I can't figure out exactly what's really going on when using the runuser -u username and su username commands.
UPDATE (thanks to @Kusalananda)
Okay, what's wrong with permissions?
root@someuser:/somehome# runuser -u app "source /etc/app/secrets/env; /somehome/way/app &" &
[4] 479621
root@someuser:/somehome# runuser: failed to execute source /etc/app/secrets/env; /somehome/way/app &: Permission denied
^C
[4] Exit 1 runuser -u app "source /etc/app/secrets/env; /somehome/way/app &"
root@someuser:/somehome#
root@someuser:/somehome#
root@someuser:/somehome# ls -ld /etc/app/secrets/env
-r-------- 1 app nogroup 1126 Apr 1 15:15 /etc/app/secrets/env
root@someuser:/somehome# ls -ld /etc/app/secrets
drwx------ 2 app nogroup 4096 Apr 1 15:15 /etc/app/secrets
root@someuser:/somehome# ls -ld /somehome/way/app
-rwxrw-r-- 1 app someuser 348528086 Mar 31 22:23 /somehome/way/app
root@someuser:/somehome# ls -ld /somehome/way/
drwxr-xr-x 3 someuser someuser 4096 Apr 1 09:30 /somehome/way/
or i now trying to run like this:
runuser --pty -u app -- bash "source /etc/app/secrets/env && /somehome/way/app &"
bash: source /etc/app/secrets/env && /somehome/way/app &: Permission denied
The first(original question): Problem was $(), thanks to @Kusalananda
I want to point out that I consciously run, for example, a web application as a background process.
Get to the point. I run applications/commands like this:
runuser -u someapp $(source /etc/someapp/secrets/env; /someapp)
su nginx source /etc/someapp/secrets/env && sleep 90s &
Eventually, I check ps aux or ps -A and see: app or the "sleep" commands are running as root!? What am I doing wrong? Or what I don't understand?
P.S. But running this command i get what i expected:
runuser -u testappuser2 sleep 30s &
#ps output
root 462265 0.0 0.4 9376 4224 pts/1 S 18:20 0:00 runuser -u testappuser2 sleep 30s
testapp+ 462270 0.0 0.1 5684 1920 pts/1 S 18:20 0:00 sleep 30s
$(...))? They are executed and replaced with their output before therunusercommand is even started.No such file or directory(because there is no command calledsource /etc/app/secrets/env && /somehome/way/app &), notPermission denied.