Call an application with root privileges lazarus / 32-Linux ---------------------------------------------------------------------- nightrider · 2013-10-28 13:43 Hi! I have a program that is a graphic front end for GNU tar. It is running ok. Now Iwould like to execute using root privileges. May someone here explain how can I do this? Greetings from São Paulo - Brazil Ricardo ---------------------------------------------------------------------- Dick, from the internet · 2013-10-28 16:06 Do you mean Code: [Select]sudo or Code: [Select]su -c Anything more permanent, such as setting the SUID/SGID bit, could have bad consequences, especially if other users have access to your program on your system.   regards,      geno ---------------------------------------------------------------------- greyspammer · 2013-11-02 12:49 It might turn out not to be as easy as to just use one of those two however (had a similar problem just recently). sudo needs to be configured to allow users to call it which you cannot just assume (not every distribution/admin does it). And su will ask for the root password which is not set on Ubuntu derivates. I think the easiest way would be to allow the user to configure the call in the application's preferences. There, they can specify which command they want to use and even if they want a command-line version or a GUI replacement (gksu, kdesudo, etc.). If everything has to work without configuration, then I'm afraid you have no chance but to probe for the distribution and switch between su and sudo accordingly. EDIT: Assuming the program is supposed to be distributed, that is. If it's just for yourself, you can use whatever your distribution provides. ---------------------------------------------------------------------- Dick, from the internet · 2013-11-02 15:45 Quotesudo needs to be configured to allow users to call it which you cannot just assume (not every distribution/admin does it). And su will ask for the root password which is not set on Ubuntu derivates. There is a reason that sudo needs to be configured for users.  If a user is not authorized either by inclusion in the sudoers file or given the root password, why would we, as programmers, try to bypass the system admin's policies by allowing our programs to run as root through a simple configuration? In my opinion, even a program as simple as gtar, when run with root privileges, can have devastating effects when used carelessly. But, as you stated, if one only writes applications for oneself, then use whatever method you like.   regards,      geno ---------------------------------------------------------------------- greyspammer · 2013-11-02 16:01 Quote from: geno on November 02, 2013, 04:45:14 pmThere is a reason that sudo needs to be configured for users. [...] I agree, I was just stating facts. Security concerns aside, you cannot rely on either one working as intended if you do not know the environment. Usually, there's a policy as to how users may attain root privileges. In typical home user environments, that policy comes from the distributor. In managed environments, it comes from the admin. Anyhow, the program in question must adapt to match that policy. Not the other way around (unless it's a reaaaaally good program ).