I want to copy files that require root to read/write from one system to another. My current solution is to use sudo on each system and use tee as shown.
ssh host sudo cat /etc/somefile | sudo tee /etc/somefile > /dev/null
This works but tee sends it's input to stdout so I have to send tee
's ouput to /dev/null.
I looked to the UNIX cat
and copy command cp
and did not find an answer.
See https://man7.org/linux/man-pages/man1/cp.1.html
and https://man7.org/linux/man-pages/man1/cat.1.html
UPDATED: I now realize that I should have stated that the solution needs to support sudo
so the simple solution of using cat
won't work.
For example,
ssh host sudo cat /etc/somefile | sudo cat > /etc/somefile
fails because the directory /etc
can only be written by root (in my case) and the re-direction to the file > /etc/somefile
runs under the current user (who doesn't have access to write to /etc).