Skip to content

Instantly share code, notes, and snippets.

@kyokuheki
Created February 14, 2020 15:58
Show Gist options
  • Save kyokuheki/43389db27f453dd8f8bea4b3b6216e17 to your computer and use it in GitHub Desktop.
Save kyokuheki/43389db27f453dd8f8bea4b3b6216e17 to your computer and use it in GitHub Desktop.
transfer dir/file to root permission remote dir over ssh with sudo and tar.

transfer dir/file to root permission remote dir over ssh

local to remote root

file

tar czf - -C /path/to/src/dir foo.txt bar.txt | \
ssh remote.example.net 'sudo tar zxvf - -C /path/to/dest/dir'

dir

tar -chf - -C /path/to/src/dir .' | \
ssh remote.example.net 'sudo tar zxvf - -C /path/to/dest/dir'

remote to remote

ssh src.example.net 'sudo tar -chf - -C /path/to/src/dir .|cat' | \
ssh dest.example.net 'sudo tar xf - -C /path/to/dest/dir'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment