I got the following bash script to mount a share on my machine:

BA_IP=$(ip route get | awk 'NR==1 {print $NF}' | awk -F'.' '{print $1,$2,$3"."}' OFS='.')$BA_LAST_OCTET
PROMPT="Sudo password: "

CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l)
if [ ${CAN_I_RUN_SUDO} -le 0 ]
    . getpass.sh $1 

    echo $PASSWORD | sudo -S : >/dev/null 2>&1
OUTPUT=$(sudo mount.cifs //$BA_IP/huginn/ /mnt/huginn/ -o username=fileshare,password="",rw,file_mode=0777,dir_mode=0777 2>&1)
if [ -z "$OUTPUT" ]; then
    HUGINN="Huginn... Mounted."

    HUGINN="Huginn... Error.\n"$OUTPUT
OUTPUT=$(sudo mount.cifs //$BA_IP/muninn/  /mnt/muninn/ -o username=fileshare,password="",rw,file_mode=0777,dir_mode=0777 2>&1)
if [ -z "$OUTPUT" ]; then
    MUNINN="Muninn... Mounted."

    MUNINN="Muninn... Error.\n"$OUTPUT
if [[ $1 == "--gui" ]] ; then
    zenity --info --title="Blackarmor" --text="$MSG"  2>/dev/null
    echo -e  "Mounting  Blackarmor shares... \n\n"$MSG

It works perfectly well from command line. But if I try to use it in a Nemo Action it shows the following message:

Huginn... Error.
sudo: no tty present and no askpass program specified
Muninn... Error.
sudo: no tty present and no askpass program specified

. getpass.sh just gets a password from gui or command line and put it in PASSWORD var. It's working ok, even in Nemo Action (I tested it).

The Nemo Action looks like this:

[Nemo Action]
Name=Mount Blackarmor share
Exec=/bin/bash /usr/bin/ba --gui

Anyone know how I can fix this ?

I also accept recommendations on how to run this in a better way. The same problem happens if I try to create a launcher pointing to this script on the Desktop without checking "Launch in terminal" option.


as @meuh suggested, I tried to change this:

. getpass.sh $1 

echo $PASSWORD | sudo -S : >/dev/null 2>&1

to this:

 #. getpass.sh $1

 SUDO_ASKPASS=/usr/bin/ssh-askpass sudo -A : >/dev/null 2>&1

but it showed the exact same message. ssh-askpass is the Ubuntu/Mint version of x11-ssh-askpass (I use Mint). Just to remember, it works in a laucher if I check "Launch in terminal". But I really don't like the big window that appears behind and it also doesn't work as a Nemo Action which would be preferable.

  • This is a generic error typically from executing a command as sudo, but the runtime user is not in the sudoers file. Have you verified the runtime user is allowed to execute these commands as sudo in the sudoers file?
    – EDubman
    Apr 9 '18 at 4:06
  • The runtime user is my account. I'm obviously allowed to execute sudo in my computer as my account is an administrative account. Or are launchers and Nemo Actions runned by another user ? AFAIK the user running these processes is my user. Apr 9 '18 at 17:29

Instead of writing your own password-getting command you can ask sudo to run an existing one, such as x11-ssh-askpass which on my Fedora system is in a package of the same name. You would say

SUDO_ASKPASS=/usr/libexec/openssh/x11-ssh-askpass sudo -A somecommand

and it will popup a gui for you to enter a password.

Alternatively, you can be less secure and allow sudo to run a command when there is no tty by editing the sudoers file with sudo visudo /etc/sudoers (be careful: keep a root login somewhere to rescue you if needed) and adding a line:

Defaults:myname !requiretty

for your username myname.

If you need a tty you can use a program like script to provide one whilst running the command, eg:

script <<<'SUDO_ASKPASS=/... sudo -A mycommand'

You would probably need to surround your entire script with script, or you would get a new tty each time, and sudo would ask you for a password each time.

  • See my edit. :) Apr 10 '18 at 3:37
  • Perhaps you can use script to provide a tty cheaply. See my addition.
    – meuh
    Apr 10 '18 at 18:19
  • Perfect. Now it worked fine. Even the Nemo Actions. Thanks. :) Apr 11 '18 at 4:24

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.