Restart the jar with root privileges for most (if not all) Linux distributions

I am developing a Java application that requires root / administrator privileges to work properly. If the user does not run the application with these privileges, I would like to notify the user and restart the program with these privileges. I figured out how to do this on Windows and OS X, but cannot find a way to do this on Linux systems. On Windows, I found a program that raises any command that you give it, in OS X you can run simple AppleScript, but on Linux, there is simply no portable way to do this.

My plan was to use gksu, but I recently discovered that it was not installed by default for most Linux systems, and none of them are Debian, so I cannot install it. Is there any portable way to restart an application with root privileges on most, if not all, Linux distributions and accessories on Java?

EDIT: I can check if the program is running as an administrator on all platforms.

+4
source share
1 answer

Linux **, Linux. sudo - , , , root, , .

, sudo ( gksudo ) - , Linux. , - Arch, , , - su.

OS X Windows, , , . Linux ​​ , , , , , .

; Linux, , , , , , , -, root : P

: , , root, , . "" Linux-land.

Hack-y answer: , gksudo gtk ( kdesudo, qt - , ..). ..), . , Linux, - . .

** , , , , , .

0

Source: https://habr.com/ru/post/1623296/


All Articles