Why echo 'password' | sudo -S sudo -s does not work whereas echo 'password' | sudo -S mount -a works?

Ralf Mardorf kde.lists at yahoo.com
Mon Feb 8 09:31:41 UTC 2021


On Mon, 8 Feb 2021 11:29:14 +0800, 孙世龙 sunshilong wrote:
>Here are the error messages:
>vc at localhost:~$ echo 'abc' | sudo -S -s
>/bin/bash: line 1: abc: command not found
>vc at localhost:~$ echo 'ccc' | sudo -S -s
>/bin/bash: line 1: ccc: command not found

Hi,

it does work with login shell bash for Arch Linux and login shell bash
for xenial (at least when running xenial in a systemd-nspawn container).


  [rocketmouse at archlinux ~]$ echo "abc" | sudo -S -s
  [sudo] password for rocketmouse: Sorry, try again.
  [sudo] password for rocketmouse: 
  sudo: no password was provided
  sudo: 1 incorrect password attempt
  [rocketmouse at archlinux ~]$ echo 'abc' | sudo -S -s
  [sudo] password for rocketmouse: Sorry, try again.
  [sudo] password for rocketmouse: 
  sudo: no password was provided
  sudo: 1 incorrect password attempt

  [weremouse at moonstudio ~]$ echo "abc" | sudo -S -s
  [sudo] password for weremouse: Sorry, try again.
  [sudo] password for weremouse: 
  sudo: 1 incorrect password attempt
  [weremouse at moonstudio ~]$ echo 'abc' | sudo -S -s
  [sudo] password for weremouse: Sorry, try again.
  [sudo] password for weremouse: 
  sudo: 1 incorrect password attempt


Are you using an alias or wrapper script for "sudo"?


  [weremouse at moonstudio ~]$ man sudo | grep "\-s," -A3
       -s, --shell
                   Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user's password database entry.  If a command is specified,
                   it is passed to the shell for execution via the shell's -c option.  If no command is specified, an interactive shell is executed.

  [weremouse at moonstudio ~]$ sudo -s lsb_release -a
  [sudo] password for weremouse: 
  LSB Version:	core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
  Distributor ID: Ubuntu
  Description:	  Ubuntu 16.04.7 LTS
  Release:	  16.04
  Codename:	  xenial
  [weremouse at moonstudio ~]$ sudo -s abc
  /bin/bash: abc: command not found


Since I'm not using an alias or wrapper scrip it doesn't mention
"line 1". However, I suspect that due to an alias or wrapper scrip,
stdin isn't used as the password, since the newline got lost. I
simulated this by replacing "echo" with "printf".


  [weremouse at moonstudio ~]$ man sudo | grep "\-S," -A3
       -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.

  [weremouse at moonstudio ~]$ printf "abc" | sudo -S -s
  /bin/bash: line 1: abc: command not found


Regards,
Ralf




More information about the ubuntu-users mailing list