Can sudo be used to always run a specified program as a particular user?
Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can sudo be used to always run a specified program as a particular user?
I'd like to always run a particular program (e.g. Eclipse) as the apache user. I used to start this program by changing its launcher to call 'su apache -c "/path/to/eclipse"' rather than '/path/to/eclipse'. (This required me to change the login shell in /etc/passwd from nologin to something like bash.)
As I'm new to sudo, I'm wondering if sudo can be used to specify that anytime /path/to/eclipse is run, that it should automatically be run as the apache user (rather than as the currently logged in user)? I get the impression that sudo might allow for this, but I'm not sure. If it doesn't, what other options do I have for 'elegantly' always running this program when launched as a given user? I find that the launcher method I described above isn't the best, because if for whatever reason I launch it a different way, I have to remember to prefix it with 'su apache'.
As far as I know it can not be used to run a program. Only give users rights to run the program. I don't think it was intended to do anything but that.
No, but, if you log in as the user and do a chmod +s /path/to/eclipse, that should turn on the "set uid" for the executable to that specific user. Note that this will allow anyone with access to that executable to run it as that user. This is often considered a gross security risk, and a no-no on a system connected to the Internet.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.