1

I want to start a long running custom script at boot. The script must run under a specific username. So far I have successfully used the screen command and switched to the user in the custom script. But I rather have the screen command run under that user so that I can later login to that user and resume the screen.

This one does work when run as root in the console but it does not work as a line in a startup script.

su -c "screen -S sessionname -d -m /path/cot/bash/script" username

1

Under GNU/Linux at boot, you should not use su (as it depends on PAM/dbus, which may not be available yet), but runuser:

runuser username -l -c "screen -S sessionname -d -m /path/to/bash/script"

When using runuser followed by the user name, the syntax is the same as su.

1

Got it, I should have used the -l flag:

su -l -c "screen -S sessionname -d -m /path/to/bash/script" username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.