Author: James Flemer
Date: 08-03-03 03:52
First off, anyone who uses ssh or scp with lots of different hosts should take the time to read the ssh_config(5) man page. It is very useful if you have accounts with different usernames, see the 'User' parameter.
Ok, now, since this article was about scp, let me talk about some nice things you can do with ssh. You all know that copying a whole directory tree sometimes causes problems, and that is why it is common to use tar to ensure permissions, ownership and symlinks are handled correctly. The example in tar(1) is:
tar -cf - -C srcdir . | tar xpf - -C destdir
Now, consider this when the destination is a remote host. Ssh can be used to make this very simple, just say:
tar -cf - -C srcdir . | ssh remote_host tar xpf - -C destdir
where 'srcdir' is on the local host, and destdir is on the remote.
Similarly, to copy from a remote host:
ssh remote_host tar -cf -C srcdir . | tar xpf - -C destdir
Another way I use ssh is to redirect output of a command on one host to a file on another host. For example, if I was compiling something and for some reason wanted the make log on another computer, I would run (using a Bourne shell):
make buildworld 2>&1 | ssh remote_host cat \> /tmp/make.log
The output of buildworld is sent over ssh to the cat process on the remote host, which just writes it to it's stdout. In this case it's stdout is redirected to /tmp/make.log. Make sure you escape the redirect (>) on the command line so it is evaluated by the remote not the local host.