Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-12-2007, 04:18 AM   #1
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 37
How to run a proccess with a diferent user?

How whouls I start a proccess as a diferent user?
More specificly, I am root and I want to run some process apart from root from my init scripts.
Let's say mysql, I don't want it to be run as root at boot but to be run as user mysql.
Old 06-12-2007, 05:35 AM   #2
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310

Rep: Reputation: 30
Hi Tux-slack,

Its as follows:-

su username
<command 1>
<command 2>

Old 06-12-2007, 05:35 AM   #3
Senior Member
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
su user
so simple
Old 06-12-2007, 05:41 AM   #4
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Are you talking about the mysql daemon (started at boot) or the mysql client?

Most daemons (background services) listen to the network. If they do so on a privileged port, then they have to be run as root to allocate the port, but they usually switch by themselves to a non-root user later on.
So the first place to check would be MySql's configuration to see if it does this already.

If it doesn't or if you want to run any process as a non-root user, you could do (as root):
su -c "the_command" non_root_user
(don't forget to enclose the commands in single or double quotes).

Or, if the program is to be run as the same non-root user all the time, you could chown' it so that the intended non-root user is the owner of the executable and then enable its setUID bit. This approach is however
not recommended and must be used with caution (for security reasons).
Old 06-12-2007, 01:47 PM   #5
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Original Poster
Rep: Reputation: 37
I don't want to simply su to another username and type commands
I know how to do that but it is useless. I was looking for something like sudo, where u can run sudo command as non-root for the command to be run as root. Didn't know that su has that option with -c
Good thing that I read the manuals oO

Oh and for mysql I ussed as example, and I meant Daemon not Client
Old 06-12-2007, 03:22 PM   #6
LQ Guru
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,247
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
if the application is installed and configured properly isn't there typically a user created specifically for those services ? so if you use the init script to start the service ( /etc/init.d/mysqld start ), the service should start with the proper user credentials

When started using the script in /etc/init.d mysqld is running under the unprivileged mysql user in the mysql group.

110 7698 0.3 1.7 118364 17620 ? Sl 16:13 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/ --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock

mysql:x:110:114:MySQL Server,,,:/var/lib/mysql:/bin/false


If it's a custom application you are thinking of, maybe you should look into HOW-TO write init scripts .. ?

Last edited by farslayer; 06-12-2007 at 03:28 PM.
Old 06-12-2007, 04:04 PM   #7
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Original Poster
Rep: Reputation: 37
Slack doesn't use SystemV init scripts, it uses BSD init scripts...
su -c will do instead of writing init scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't run Firefox from my single user(only from a super user) nightrider Linux - Newbie 14 10-24-2006 08:35 PM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM
automat proccess juanb Linux - Software 1 12-09-2003 07:47 AM
KDE in Knoppix hangs on Login as diferent user cpis Debian 0 09-24-2003 10:41 AM
How do I kill a proccess? bripage Linux - General 8 08-09-2002 08:37 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration