0

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
4
  • Why are you using command substitutions ($(...))? They are executed and replaced with their output before the runuser command is even started. Commented Apr 3 at 15:47
  • @Kusalananda it's good qustion, i saw this example, when i search to way how to do what i need, after your question, i understand this mistake now. But i now have a permissions error, but i am sure that permission is right: Commented Apr 3 at 16:10
  • @Kusalananda Added to the question Commented Apr 3 at 16:14
  • I would have expected the command to answer with No such file or directory (because there is no command called source /etc/app/secrets/env && /somehome/way/app &), not Permission denied. Commented Apr 3 at 17:03

1 Answer 1

0

bash treats the first non-option argument as file path. So

bash 'echo foo'

does not work. You need

bash -c 'echo foo'

or in your case

bash -c 'source /etc/app/secrets/env && /somehome/way/app &'

runuser --pty -u app -- bash -c 'source /etc/app/secrets/env && /somehome/way/app &'
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.