2

After downloading netbeans 10.0 I taught of creating a desktop file to launch it, So, I don't have to run sudo /home/abc/Downloads/netbeans/bin/netbeans every time.

I created small script to launch netbeans in admin priviliges.

#!/bin/sh
cd /home/abc/Downloads/netbeans/bin/ 
echo "password" | sudo -S ./netbeans

I put this file to /usr/bin/ and

created netbeans.desktop file as follows

[Desktop Entry]
Version=1.0
Type=Application
Terminal=False
Exec=/usr/bin/netbeans
Name=Netbeans
Comment=Java IDE
Icon=/home/abc/Downloads/netbeans/nb/netbeans.icns

by typing

netbeans in terminal it opens netbeans in admin privileges.

But clicking the desktop file or shell file doesn't respond anything

Sorry if it is silly I am a Newbie.

EDIT

Tried everything stated here => How do I run a 'sudo' command inside a script? but nothing worked.

As @dessert suggested to use pkexec. It works but gives another problem.

/home/abc/Downloads/netbeans/platform/lib/nbexec: WARNING: environment variable DISPLAY is not set

I think netbeans needs terminal to run. and so I tried xdf-open and gksu but non of them worked. Please help!

1 Answers1

1

The large majority of user applications should never be run as root. If root permissions are required, it would be very bad practice to allow user to run applications with root permissions just by clicking a launcher without any form of authentication.

Fortunately, it is not easy to run scripts outside of the terminal with admin privileges. The GUI menu system does not allow to easily create launchers that launch programs with root permissions without any security measures.

In rare cases, there is a need to have graphical user interfaces perform administrative actions. Previously, the gksudo command allowed a user with root privileges to launch just any graphical application with root privileges. This poor security model has been depreciated in favor of more secure systems that either 1) do not require that a graphical user interface is run as root at all, but still allow for access to system files and folders, or 2) still run the entire graphical application as root, but have a stronger security in place.

1) is covered by the "admin://" URI. Applications such as gedit and nautilus can be started with such an URI, e.g. as in

gedit admin:///etc/fstab

With this approach, gedit itself just runs as the normal user. The system provides it with a temporary copy of the system file, in this example /etc/fstab. Once the user saves the temporary copy, the system updates the original /etc/fstab. Also "Disks" is designed this way. The application, i.e., the graphical user interface, runs as normal user anytime, but requests the administrator password at a point where an administrative task is about to be performed.

2) is handled through pkexec. Here, after authentication, the entire application is started with root permissions. This is also how gksudo used to work. The big difference, however, is that, additionally, a system policy file about the application must be in place. Thus, only previously authorized applications can be started as root by the privileged user.

vanadium
  • 97,564