I have an ssh gateway (let’s call it gate
) that I use to access my internal network. On that net, I have a machine (let’s call it stuff
) with stuff I want. A lot of stuff. And I want to use tar
to preserve the permissions and symlinks and stuff on the files. I’ve done this before, but that knowledge is lost to the misty times of the dot-com days. But I re-figured it out:
From somewhere out on the net…
Try to log into the internal machine:
somewhere% ssh -t gate 'ssh stuff'
This gets you logged into the machine called ‘stuff’ on the private net protected by ‘gate’. The -t
flag is to force pseudo-tty allocation, since ssh normally won’t do that when input is stdin.
Copy a file by hand:
somewhere% ssh -t gate 'ssh stuff cat "~/some/file.txt" ' \
> some_file.txt
Yeah, the quoting is going to get sucky if you keep this up.
Tar up a whole filetree, saving the tarball:
somewhere% ssh -t gate 'ssh stuff tar cpzf - "~/some/directory/" ' \
> some_directory.tar.gz
Copy a few filetrees (with relative paths and spaces) to your local drive:
somewhere% ssh -t gate 'ssh stuff "cd some/directory; \
tar cpzf - one\ dir two\ dir"' | tar xvzf -
Some of you old fogeys may recognize this pattern as how we moved directories between filesystems in the days when mv
wouldn’t let you.