Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run command with sudo #584

Closed
jparsert opened this issue Apr 5, 2017 · 6 comments
Closed

Add ability to run command with sudo #584

jparsert opened this issue Apr 5, 2017 · 6 comments
Assignees
Milestone

Comments

@jparsert
Copy link

jparsert commented Apr 5, 2017

Bascially what the title says. It would be grate to be able to run a program with sudo.

@DaveDavenport
Copy link
Collaborator

sudo won't work. as you need to enter a password.
I will add a binding that you can setup a custom command accomplishing this, f.e. bind a key to run 'gksudo {cmd}'.

@jksf
Copy link

jksf commented May 10, 2017

For anyone interested here is i3wm binding example:

bindsym $mod+Shift+d exec --no-startup-id "rofi -show drun -run-command 'gksudo {cmd}'"

or more generally:

rofi -show drun -run-command 'gksudo {cmd}'

@DaveDavenport
Copy link
Collaborator

Thinking about it, and talking it over. I think @jstefanski is the best/cleanest solution.

Closing.

@jstefanski : Thanks.

@ivanbartsov
Copy link

ivanbartsov commented Apr 26, 2018

Thought I'd necrobump this: there's a way to do this without gksudo using rofi for password input.
sudo itself has a -A option that makes it pipe the prompt and take the pass from stdout of whatever is in the SUDO_ASKPASS environment variable.

So, we make a rofi-powered askpass script, say ~/bin/askpass-rofi:

#!/bin/sh

# Take password prompt from STDIN, print password to STDOUT
# the sed piece just removes the colon from the provided
# prompt: rofi -p already gives us a colon
rofi -dmenu \
	-password \
	-no-fixed-num-lines \
	-p "$(printf "$1" | sed s/://)"

Then to run something as root, we do:

SUDO_ASKPASS=~/bin/askpass-rofi rofi -show drun -run-command "sudo -A {cmd}"

This is probably something to bind to a "run as root" hotkey in your DE.

Alternatively, you could just add the environment variable to your usual rofi binding (mine is ALT+F2)

SUDO_ASKPASS=~/bin/askpass-rofi rofi -show run

and just type sudo -A YOUR_COMMAND each time you want to sudo something -- this way the whole ritual is very similar to what you usually do on the commandline.

PS @DaveDavenport, this could be put into the FAQ section of the wiki, not sure how frequent this topic is :)

@jazoom
Copy link

jazoom commented Sep 29, 2019

For anyone interested here is i3wm binding example:

bindsym $mod+Shift+d exec --no-startup-id "rofi -show drun -run-command 'gksudo {cmd}'"

or more generally:

rofi -show drun -run-command 'gksudo {cmd}'

For anyone in the future who is confused why this doesn't work via sxhkd, it's because sxhkd strips out the {}. Escaping them seems to work:

rofi -show drun -run-command 'gksudo \{cmd\}'

@astrolemonade
Copy link

Thought I'd necrobump this: there's a way to do this without gksudo using rofi for password input.
sudo itself has a -A option that makes it pipe the prompt and take the pass from stdout of whatever is in the SUDO_ASKPASS environment variable.

So, we make a rofi-powered askpass script, say ~/bin/askpass-rofi:

#!/bin/sh

# Take password prompt from STDIN, print password to STDOUT
# the sed piece just removes the colon from the provided
# prompt: rofi -p already gives us a colon
rofi -dmenu \
	-password \
	-no-fixed-num-lines \
	-p "$(printf "$1" | sed s/://)"

Then to run something as root, we do:

SUDO_ASKPASS=~/bin/askpass-rofi rofi -show drun -run-command "sudo -A {cmd}"

This is probably something to bind to a "run as root" hotkey in your DE.

Alternatively, you could just add the environment variable to your usual rofi binding (mine is ALT+F2)

SUDO_ASKPASS=~/bin/askpass-rofi rofi -show run

and just type sudo -A YOUR_COMMAND each time you want to sudo something -- this way the whole ritual is very similar to what you usually do on the commandline.

PS @DaveDavenport, this could be put into the FAQ section of the wiki, not sure how frequent this topic is :)

This is not working ! The rofi menu doesn't even show,can you be more clear about this setup ?

@davatorium davatorium locked as resolved and limited conversation to collaborators Feb 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants