I'm using (X)dialog for a script that a normal runs, but it needs root privileges for some commands. The script runs from a .desktop file, thus the user sees no terminal. For example here

Xdialog --msgbox "Welcome" 0 0
touch /root/testfile
Xdialog --msgbox "All OK" 0 0

the touch command does not execute. One solution would be to use kdesu

kdesu touch /root/testfile

but this approach has two problems: the user has to provide the password for every command and the window of kdesu does not follow the same theme as the rest of the windows.

Note that I want the user to provide the root password and not being a sudoer.

I have found a similar script here, but I cannot apply it on my script, as the actual command cannot accept the password as the sshpass does.

  • Are you opposed to using sudo? – eyoung100 Aug 21 '15 at 22:51
  • Yes, user should provide the root password, not his own. – Theo Aug 21 '15 at 23:16
  • You have 3 choices: 1. Convert your script to ncurses, and get rid of X, and use su as intended, 2. keep the X integration and use sudo with his own password. 3. Convert your script to an actual UI, and use themes. – eyoung100 Aug 22 '15 at 0:27

A way to do this would be to just execute su at the beginning of the script. The user enter the root password only once at the beginning of the script. You can then execute commands without root privileges by doing su [username] -c [your command not to be executed with root privileges].

However, you can't use dialog boxes to ask for the password here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.