Yo how do I run an executable script that requires sudo privileges, without ever touching the command line? I want it to just prompt me for my password the GUI way and be done with it.

How do I write a script so that, instead of just failing and doing nothing, it brings this up?

@bignose, @sotolf and @undefined provided answers that probably would work, if I had the respective programs installed. @jinxd solution probably would work, but I prefer having to input the password.

@yyp Hit the jackpot, as it turns out pkexec is what I have on my system. So just putting "pkexec" at the start of the script makes it ask for password and everything works as intended. Thanks, everyone!

@cirno Idk where the program is located but I suggest looking at where the program is that brings that up and invoking it first. Then possibly find a way to export the privileges that it gives and move to the next program you need.

@Zach777 It does not appear to be a standalone program. In the screenshot, I invoked it by just typing "gufw" into the console. I can avoid it by typing "sudo gufw" and giving my password in the terminal.

With the script I'm trying to use (mount command), If I type it in without sudo it throws an error because I'm not root. Putting sudo into the script does not help.

@cirno Try seeing what all gufw calls? Trace what it does.

@cirno The `--askpass` command line option lets you specify a program which will prompt the user for input and emit the passphrase for `sudo` to read it. The same thing can be specified with an environment variable or a configuration option.

See `sudo(8)`, the `--askpass` option.

@cirno This allows you to make use of the existing program (designed for SSH, but works fine for this purpose also) `ssh-askpass` and equivalents, like `ssh-askpass-gnome` etc.

@cirno If you're ok with that program being run without sudo password, add nopass to sudoers file for the user, for that executable

@cirno I think there is a program called gksudo or something close to it that can do that. Or at least it did exist before :p

@cirno I think you can use sshpass for this

sshpass -P 'sudo prompt' -p 'sudo password' sudo ufw
If you want, you can use a password manager, like pass to save the sudo password or encrypt it with gpg so you don't have your password saved in plain text.

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.