3

From my mono application, running under Linux, I want to run another one as root user. At the moment I use Process.Start, running gksudo.

This solution works quite well under one condition - there is gksudo installed.

I need a mechanism to elevate privileges for a mono assembly (not necessarily as another process) that does not rely on a particular, desktop-dependant application like gksudo or kdesu and is not console-based (like good ol' sudo).

Actually I believe I need a way to PAM-ify my application.

The solution does not have to be Windows compliant, but it would be a nice bonus.

I've seen many possible answers to my problem, but none did resolve all the issues.

A very nice approach was https://stackoverflow.com/a/16276287/882200, but it requires an assembly to be ran as root, which is not possible.

This inspired me to try a new approach. I've tried running

Process.Start("whoami", "otheruser", password, "");

The output should be otheruser, but it is not.

Please mind that I leave the domain (last parameter) empty (is that OK?) and I fill password according to this example.

This solution is not the best one - it requires me to provide means to grab a password, but it is acceptable, although not working.

The best option for me would be to make my environment choose the correct way to receive a password - either by a Qt/GTK popup or a console prompt.

The last thing to keep in mind - to run an app as root I'd love to be able to provide a sudoer password, not necessarily a root password (according to sudoers configuration).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Piotr Zierhoffer
  • 5,005
  • 1
  • 38
  • 59
  • Did you ever find a solution for this? I'm porting a .net application from Windows to Linux, and one component is an update system. On Windows it uses ProcessStartInfo.Verb = "runas" to invoke a UAC prompt, but I can't find a reliable alternative for Mono on Linux. – Ashley May 25 '18 at 23:25
  • Not really, no. Unfortunately we stick to the "try gksudo, else try beesu, etc, etc". Does the "runas" verb work with no problems? – Piotr Zierhoffer May 28 '18 at 10:02
  • Using 'runas' has been working flawlessly for me under Windows, but doesn't work on Linux. I've now taken the route of having an update service running in the background as root, and having the client software communicate with it using sockets whenever it wants to initiate a software update. – Ashley Jun 01 '18 at 01:32

0 Answers0