I\'m trying to login to a ssh server and to execute something like:
ssh user@domain.com \'sudo echo \"foobar\"\'
>
Another way is to run sudo -S
in order to "Write the prompt to the standard error and read the password from the standard input instead of using the terminal device" (according to man
) together with cat
:
cat | ssh user@domain.com 'sudo -S echo "foobar"'
Just input the password when being prompted to.
One advantage is that you can redirect the output of the remote command to a file without "[sudo] password for …" in it:
cat | ssh user@domain.com 'sudo -S tar c --one-file-system /' > backup.tar