1

I'm new to dmenu. I'm trying to run programs which need sudo permission with dmenu. I've followed this link. So I have script ./dpass in my bin folder which says:

#!/bin/bash
dmenu -p "$1" <&- && echo

I've also run the command:

$ export SUDO_ASKPASS=/home/username/bin/dpass

So now I have a script in my bin folder called shutdown. It says:

#!/bin/bash
sudo -A shutdown -h now

When I try to run it through dmenu, it does ask me for my password, but the problem is that when I type the password the password is not hidden. I find this really insecure since anyone can see my password. Is there anyway to hide passwords in dmenu?

3 Answers 3

2

Try removing the && echo from the end of the call to dmenu:

#!/bin/bash
dmenu -p "$1" <&-

This should disable the echoing of what the user is typing into dmenu. This method is covered in this blog post titled: Enter passwords from dmenu.

excerpt
$ cat dpass
#! /bin/sh

# shellcheck disable=2046
caller="$(ps -o comm= -p $(ps -o ppid= -p $$))"
prompt="${1:-[$caller]}"
promptfg=black promptbg=red hidden=white
font="Liberation Sans-20:Bold"

dmenu -p "$prompt" -fn "$font" \
  -nf "$hidden" -nb "$hidden" -sf "$promptfg" -sb "$promptbg" <&-
  1. It sets the prompt (red part) to the calling application, if no args were passed. So the user always gets a prompt of some kind.
  2. It removes the trailing && echo statement, so it works on other password handlers.
2
  • I have removed the echo from dpass but it is still not working Commented Aug 21, 2018 at 11:16
  • @eddard.stark - can you show us some output from this? Commented Aug 21, 2018 at 13:25
1

Inspired by Fuseteam, I wrote a script called stprompt:

#!/bin/bash

prompt="$1"
answer=$(st -o "-" -g 100x5 -c st-prompt sh -c "echo -n '$prompt: '; read -s ANSWER; echo \$ANSWER")
echo "${answer#*: }" | tr -d '\r'

This script prompts the user, hides the input, and will output the response.

For your specific case, you could use this script in this manner:

sudopgm==$(echo "${options[@]}" | dmenu -i -p 'Programs that need sudo: ')
SUDO_ASKPASS=$(stprompt "sudo pass") sudo -A $sudopgm

enter image description here enter image description here

There's more information about how I use stprompt in my dotfiles readme, and an example usage in my dmenu_ibmicmd script.

As Fuseteam said, st is a terminal. You can replace it with your favorite terminal.

0

a work around could be a script named say dterm that runs this:

#!/bin/bash
command="$@";st -- $command

that way when you run dterm sudo command it'll pop up a terminal for password input

as a added bonus you can also run any terminal application throught dmenu

p.s. st is a terminal it can be replace with any terminal that accepts the -e or -- argument

p.p.s this assumes you can execute your script through dmenu

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.