When I use sudo twice in two piped commands, I get the following output:
$ sudo echo 'hello world' | sudo cat
[sudo] password for zoey: [sudo] password for zoey:
And must enter my password twice. The first time, it is hidden as usual, but the second is shown in plaintext.
$ sudo echo 'hello world' | sudo cat
[sudo] password for zoey: [sudo] password for zoey:
password123456seven
hello world
After the command exits, anything I type to the command line is hidden, as if I were typing a password, although command outputs work (mostly) fine. This behaviour continues until I close the terminal.
I tried:
$ echo 'hello world' | sudo cat
$ sudo echo 'hello world' | cat
And both seem to have normal behaviour.
I don't want to have to use $ sudo bash -c "echo \'hello world\' | cat"
, which seems overly clunky, and would make quoted text a nightmare to handle.
Also, before anyone asks, yes, I know that echo
and cat
don't often require root permissions.
Not sure if this makes you feel better, but what you are observing doesn't occur in Ubuntu 16.04. It does occur in Ubuntu 15.10 (which is what I presume you're using...or perhaps something older?).
Fortunately, I have a 16.04 and a 15.10 machine to try. Under 16.04, I only have to enter the password once.
Not sure where the difference is, though. I just checked and both are using the same version of bash (4.3.42). I don't believe there are any settings in my .bash* files that is changing the behaviour...
(Perhaps you can try an Ubuntu 16.04 boot disk to confirm yourself what I'm seeing?)