How to run a program on startup not as root?

227 Views Asked by At

Having some issues with this. I have the following script:

cd /home/program
screen -S program -d -m ./program.sh

In /etc/init.d and it runs on startup.

Which works fine, but it runs it as root, I don't want it to run as root. I have tried using su programs-user then doing the screen but it only opens the screen and nothing else. I think it's a permissions thing but I'm not entirely sure as I'm not that familiar with linux.

Edit: this is what I got right now
su username -c "screen -S screen_name -d -m bash -c 'cd /home/user && ./program'"
And it doesn't do anything.

Edit2: I'm guessing cause the user doesn't have permission to run screen, don't know how to give that permission.

Edit3: Ok when I login with the username it is in fact working, but when I type screen -ls as root I don't see the screens

1

There are 1 best solutions below

0
On
#!/bin/bash

screen -dmS screen_name
screen -S screen_name-p 0 -X stuff $'su username\n'
screen -S screen_name-p 0 -X stuff $'cd /home/username\n'
screen -S screen_name-p 0 -X stuff $'./program\n'