I need to pipe data through SSH to a command that reads stdin. The command needs to run with sudo
so I need to be able enter the sudo password, too. Without ssh, I'd use numbered file descriptors like so:
$ (sudo tee /tmp/test <&3; cat /tmp/test) 3<<< "test"
sudo: password for confus@confusion, running as root: ***********************
test
test
With SSH, this same approach doesn't seem to work:
$ ssh [email protected] -t "sudo tee /tmp/test <&3; cat /tmp/test" 3<<< "test"
Warning: Permanently added 'somehost.com' (ED25519) to the list of known hosts.
bash: line 1: 3: Bad file descriptor
Connection to 10.17.6.12 closed.
Is there some other way to make this work?
Edit: related question
sudo
should ask for password via/dev/tty
, so you can simply use stdin for data (e.g.echo test | sudo tee /tmp/test; cat /tmp/test
). Withssh
there is a general problem though, explained and solved here: ssh with separate stdin, stdout, stderr AND tty. Is this what you need?