In case your /desired/path
on your destination machine has write access only for root, and if you have an account on your destination machine with sudo privileges (super user privileges by prefixing a sudo
to your command), you could also do it the following way:
Option 1 based on scp:
- copy the file to a location on your destination machine where you have write access like
/tmp
:
scp file user@destinationMachine:/tmp
- Login to your destination machine with:
ssh user@destinationMachine
- Move the file to your
/desired/path
with:
sudo mv /tmp/file /desired/path
In case you have a passwordless sudo setup you could also combine step 2. and 3. to
ssh user@destination sudo mv /tmp/file /desired/path
Option 2 based on rsync
Another maybe even simpler option would be to use rsync
:
rsync -e "ssh -tt" --rsync-path="sudo rsync" file user@destinationMachine:/desired/path
with -e "ssh -tt"
added to run sudo without having a tty.