LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-04-2003, 08:25 AM   #1
Guru3
Member
 
Registered: Sep 2003
Location: //home/sweden
Distribution: RedHat 9, Fedora Core 1
Posts: 360

Rep: Reputation: 31
How to run a program as a different user?


Say I'm logged in as root, but I want to run a program as a normal user, because that's the only way it will run, and I don't want to log out then log back in again. Yes, I know I could do ALT+F2 or something and go to a different terminal, but that's logging in again, and my password is difficult to type, so I don't want to do that. Is there some trick to running a program as a different user?
 
Old 11-04-2003, 08:40 AM   #2
djtoltz
Member
 
Registered: Nov 2003
Location: Eastern North Carolina, USA
Distribution: Mandrake
Posts: 51

Rep: Reputation: 20
from root, you can "su" to any user you want without needing a password.

e.g. "su admin", hit enter, and you're admin. If you need admin's environment, use "su - admin".

Finally, if you just want to run one command as "admin", you can use;
su -c "somecommand <arguments>" admin

... which will run somecommand as user admin then return.

Use "man su" for more details on how to use the "set user" command.
 
Old 11-04-2003, 08:55 AM   #3
linuxbotx
Member
 
Registered: Oct 2003
Location: USA
Distribution: Fedora Core 4
Posts: 247

Rep: Reputation: 30
Or you could log in as your user, go to a console in X, type su and run that app as root. But why would you want to change users??? Its not very secure. Now, you will have to run some apps as root, but constantly changing users is stupid.

But to answer your question, create an icon on your desktop to run the app. Right click on the icon, click properties. Click on the tab called execute
click on the checkbox called "Run as differen't user" and type in the username in the little text box under it.
 
Old 11-04-2003, 11:59 AM   #4
Guru3
Member
 
Registered: Sep 2003
Location: //home/sweden
Distribution: RedHat 9, Fedora Core 1
Posts: 360

Original Poster
Rep: Reputation: 31
Ok, thanks for your reply. The reason I ask this is in RH9 there is /etc/rc.local which runs programs at startup. Unfortunately it runs them as root so I need to set it to run them as a regular user, because some programs don't recomend being run by root/won't be run by root.
 
Old 11-04-2003, 12:35 PM   #5
Guru3
Member
 
Registered: Sep 2003
Location: //home/sweden
Distribution: RedHat 9, Fedora Core 1
Posts: 360

Original Poster
Rep: Reputation: 31
I got this
Quote:
You'd use 'su -c "..." <user>' for rc.local.

Does this answer your question?

Also, to make it easier to deal with quotes and such, it's generally easier to write a script that requires no arguments and passes required arguments to the program, does redirection, etc. You then call the script with su -c <scriptname> <user> and let the script do all the setup, redirection, etc. which is already running as <user>.
from djtoltz in an e-mail and it worked perfectly! Thanks!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run program as different user h2gofast Linux - Newbie 2 11-26-2005 12:05 PM
Need to have program run as different user exodist Linux - Software 5 10-26-2005 10:07 PM
Run program as user falcon Linux - Newbie 1 11-07-2004 11:17 AM
How Do I Run A Program As A Different User?? Wolf-67 Linux - Newbie 3 10-04-2004 12:26 PM
run program after user logs in kinasz Linux - General 2 09-22-2004 03:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:48 PM.

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