A question come up today about the best way to get files around between a Mac OS X box and a Fedora Core 6 box:
Me: Definitely scp. Him: But I'm not a Unix person. Me: It's just like cp, only better. Him: I'll look it up. (Typed "man scp" in a terminal bash prompt on the N" MacBook Pro laptop, but the machine is pegged and nothing would show up.)
Before I started using scp, I used ftp to move files between my machines. It does what needs to be done, and I was content in using it. Then one day someone (I think it's Jonathan) said "I've put the package on the CVS server. You can use scp to get it." That's my first encounter with scp. Actually it was PSCP because I was using PuTTY on a Windows box at the time.
I did the Googling, and manning, and printing and reading, and finally figured it out. It's non-trivial, the setting up of ssh is, the hard part being the generation (and the safe-keeping) of the key pairs. However, once that is done, the rest is easy. To do the actual work, the target machine needs to have a running sshd daemon. And on both Mac OS X and Fedora Core 6 Linux it is fairly easy to turn on sshd.
Now, scp. Scp stands for "secure cp" where cp is short for "copy." So scp allows you to securely copy files around.
In the following low-tech screencast (you have to imagine me typing the commands in and getting the responses that followed), I created a file "dummy.txt" and copied the file three times, once locally on gao-2006 (My Fedora Core 5 workstation), once local-to-remote to gao-2005 (my Mac mini), and once remote-to-remote from gao-2005 to gao-2002 (my web server, a.k.a. www.weiqigao.com):
[weiqi@gao-2006 ~]$ mkdir scp-demo
[weiqi@gao-2006 ~]$ cd scp-demo/
[weiqi@gao-2006 scp-demo]$ echo This is a test. > dummy.txt
[weiqi@gao-2006 scp-demo]$ ls
dummy.txt
[weiqi@gao-2006 scp-demo]$ scp dummy.txt copy_of_dummy.txt
[weiqi@gao-2006 scp-demo]$ ls
copy_of_dummy.txt dummy.txt
[weiqi@gao-2006 scp-demo]$ scp dummy.txt gao-2005:/Users/weiqi/copy_of_dummy.txt
dummy.txt 100% 16 0.0KB/s 00:00
[weiqi@gao-2006 scp-demo]$ ssh gao-2005 ls copy_of_dummy.txt
copy_of_dummy.txt
[weiqi@gao-2006 scp-demo]$ scp gao-2005:/Users/weiqi/copy_of_dummy.txt \
gao-2002:/home/weiqi/copy_of_copy_of_dummy.txt
copy_of_dummy.txt 100% 16 85.8KB/s 00:00
Connection to gao-2005 closed.
[weiqi@gao-2006 scp-demo]$ ssh gao-2002 ls copy_of_copy_of_dummy.txt
copy_of_copy_of_dummy.txt
[weiqi@gao-2006 scp-demo]$
Notice that when copying file locally, scp is just like the regular cp on Unix/Linux or copy on Windows. Once you understood that, copying files remotely is easy to comprehend: you just have to use the "host:/absolute/path/to/file" format to address the remote file. Note also that both arguments can be remote files.
It just so happened that I have accounts set up on these machines that bear the same login "weiqi". Had the logins been different on different machines, I would need to use the "login@host:/absolute/path/to/file" format to address the remote file.
Had I not had ssh-agent running and my private key cached by it, scp would have prompted me for the passphrase of my key store.