I'd like to do something like:
scp local_file remote_server:/some_directory
But in order to gain privileges to /some_directory, we need to call
sudo. I know that a similar question had already been asked quite a few times here, but most of the answers either took advantage of
sudo's password caching (which for some reason doesn't seem to work for me in two consecutive
ssh calls) or the fact that we're root (so we can set up a passwordless
sudo or make SSH let in root).
In the latter, both of the solutions seem insecure, so I'd rather like to assume that we're not calling
sudo to become root and thus can't reconfigure the system. What can be done in such a situation to simply copy a file?
Here are my attempts so far:
( read -s -p 'Enter password: ' pass; echo $pass ; tar cf - local_file ) | ssh -t -t remote_server 'sudo tar -C /some_directory' )
Is there a better way?