beta.blog

Linux (Ubuntu)

Ubuntu: Execute an application under a different user account

by on Aug.11, 2010, under Linux (Ubuntu)

Here’s a short tutorial about how to start an application via a daemon user.
It has the advantage that the application is not being started via root account and therefore only gains limited access to your server, which eliminates many vulnerabilities.

1. Step one :
Create a new file called start.sh. I used the text editor vim to do so :

vi start.sh

2. Insert the following code into your batch file :

#!/bin/bash
echo "Starting GTA SA Server on port 7778"
su -m user1 -c "cd /opt/gtasa-dedicated/;/opt/gtasa-dedicated/samp03svr 1>/dev/null 2>&1&"

In my example the daemon user is called user1, the applications path is /opt/gtasa-dedicated/ and the full path to my target executable file is /opt/gtasa-dedicated/samp03svr

3. Save your file via CTRL+ZZ
4. Make it executable via chmod a+x start.sh
5. Execute it via:

./start.sh

After completing those steps, you can type top into your terminal in order to access a list of currently running processes. You will also see which user started the process, in my case it would be user1.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!