2

Whenever I am running any command with sudo, No password is asked from stdin. Instead, it automatically takes a password from somewhere and fails. Once All attempts are exhausted, my command is ultimately failed. I am not able to open the sudoers file too.

I also tried echo PASSWORD | sudo ls. Here too it is taking the wrong password.

ank@ank-aqua-pc:server$type -a sudo
sudo is /usr/bin/sudo

ank@ank-aqua-pc:server$sudo -l Sorry, try again. Sorry, try again. sudo: 3 incorrect password attempts

Ankush K
  • 225

1 Answers1

1

The man sudo is saying (Source)

-S, --stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. The password must be followed by a newline character.

and you need to specify the user that this password is used for

The correct command is

PASSWORD="abc\n" #The \n is for newline character
echo $PASSWORD | sudo -S -u <username> <command
  • ank@ank-aqua-pc:aquasec$echo $PASSWD | sudo -S -u ank ls

    sudo: pam_open_session: Module is unknown sudo: policy plugin failed session initialization This replied with error pam_open_session.: Module unknown. Looks like some one was stuck with same issue but did not get fix. https://askubuntu.com/questions/1291697/pam-open-session-module-is-unknown

    – Ankush K Mar 14 '21 at 10:37