Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you make an executable file (a shell script not of my own creation), when be accessed, pop up a little window requesting the password (as of now it is set to all executable, owner read and right, group and others only read.)

share|improve this question
Call gksu or kdesudo, which show the dialog and run the program as root. From a script, call those utilities around the part that requires root permission. – Mechanical snail Jan 18 '13 at 0:32
What kind of executable file? Are you programming now in C++ for example and trying to find a way to integrate with PolicyKit for example? Or do you mean in scripting like gksudo? – gertvdijk Jan 18 '13 at 0:33
up vote 3 down vote accepted

Rather than touching the current shell script, you can make a wrapper to call it with more permissions.

Save the script from below, make it executable (e.g. chmod +x, and use it like this:

./ /path/to/

Then make the only runnable by root:

chown root:root /path/to/
chmod go-x /path/to/

Test it:

bash: /path/to/ Permission denied

Via wrapper script as above should work. From here you should be all set.

# Wrapper to run commands with sudo. Uses gksudo in a GUI environment, falls back on 
# plain sudo in non-GUI environment.
# Info:
# Author(s): Gert van Dijk
# Disclaimer: No warranties whatsoever. I'm not responsible for any damage here.
# Purpose of this script is to *demonstrate* a wrapper to run other commands.

gui_sudo () { # Run command with a GUI-capable sudo-wrapper
    $GKSUDO -- $SUDO "$@"

plain_sudo () { # Run command with the plain sudo wrapper
    $SUDO "$@"

has_gui () { # Checks for whether GUI is available via the $DISPLAY environment
    if [ "$DISPLAY" != "" ]; then return 0; else return 1; fi

has_args () { # Checks for valid amount of arguments
    if [ "$1" != "" ]; then return 0; else return 1; fi

print_usage () { # Prints usage
    echo "Usage: $0 <command> [args]"

if has_args $@; then
    if has_gui; then gui_sudo $@; else plain_sudo $@; fi
    print_usage; exit 1
share|improve this answer
I seem to be getting this error (which I no not how tho fix since it has been a bit since I have played with bash.) chris@Chris-Laptop-Ubuntu:~$ ~/bin/Sudoer /usr/bin/minecraft /home/chris/bin/Sudoer: line 31: syntax error: unexpected end of file (Oh yes, and if you are wondering why I am doing this to minecraft, it is because I like it when people have to ask me to go on minecraft. POWER) – PyRulez Jan 18 '13 at 19:29
@PyRulez Seems like you're right :) I was trying too hard to get it more compact, but made a mistake. Now copy the script again. – gertvdijk Jan 18 '13 at 19:36
It seems (and this worked by the way) that I had to rename the original script to something new, and then make another script with the same name which runs ./ /path/to/ – PyRulez Jan 19 '13 at 23:18
Oh yes, and when I do that it works like a charm (an evil charm that allows me to control others, mu ha ha.) Thank you. – PyRulez Jan 19 '13 at 23:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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