I need to run command as another user and write to its stdin and read from its stdout.
I can run command as another user only via opening new shell: sudo su anotheruser
but with new opened shell i will lost stdin and stdout of caller. I am not allowed to run sudo -u anotheruser -c command
I found out that i can use named pipes for stdin/stdout redirection, so i wrote a script:
#!/usr/bin/env bash
mkfifo pipein
mkfifo pipeout
echo '/usr/lib/openssh/sftp-server 0<pipein >pipeout' | sudo su anotheruser
cat 0<&1 >pipein & cat <pipeout
wait
But it doesn't work as desired. I want to redirect script's stdin to command's stdin and also redirect command's stdout to script's stdout - so i could seamlessly use the script as original command.