I have a simple bash script like this:

#!/usr/bin/env bash

sudo ./some_other_script_01
sudo ./some_other_script_02

When I execute this script, I always see the password prompt, as usual:

[sudo] password for user: 

However sometimes, inexplicably, before I have typed my password, ./some_other_script_01 starts getting executed (presumably without root permissions). This happens even though it did prompt me for a password (which I didn't yet provide).

Currently, when this happens, I have to kill the scripts and start again (so that they get executed with root privileges).

  • 1
    Is sudo configured with passwd_timeout set to some too small value in the sudoers file?
    – Kusalananda
    Mar 7, 2019 at 21:56
  • If you want to force sudo to ask for a password, use the -k option. Check your man page for details. Mar 7, 2019 at 22:18

1 Answer 1


Sudo once is enough, just start the wrapper.sh with sudo. Check if you have root permission in the script no more sudo calls needed.

sudo ./wrapper.sh


#!/usr/bin/env bash

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"

  • 1
    Thank you. I've marked this as the answer because it's the right thing to do, but it still doesn't solve my mystery. I will keep investigating.
    – logidelic
    Mar 8, 2019 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .