Securely Copy Files Between Hosts


scp

If you're in a hurry and you need to copy a file securely from one machine to another, scp (secure copy) is what you want. In essence, here's the basic pattern for using scp:

scp user@host1:file1 user@host2:file2 


This is basically the same syntax as good ol' cp, but now extended to the network. An example will make things clearer. Let's say you want to copy backup.sh from pound (192.168.0.15; username ezra) to /home/tom/bin on eliot (129.168.0.25; username tom) using scp:

$ pwd /home/ezra $ ls ~/bin backup.sh $ scp ~/bin/backup.sh tom@192.168.0.25/home/tom/bin backup.sh              100% 8806     8.6KB/s   00:00 $ 


You weren't prompted for a password because you set things up earlier in "Securely Log In to Another Machine Without a Password" so ssh doesn't require passwords to connect from pound to eliot, and because scp relies on ssh, you don't need a password here, either. If you hadn't done that, you would have been asked to enter tom's password before continuing.

Let's say you have several JPEGs you want to transfer from pound to eliot. No problemjust use a wildcard:

$ ls -1 ~/covers earth_wind_&_fire.jpg handel_-_chamber_music.jpg smiths_best_1.jpg strokes_-_is_this_it.jpg u2_pop.jpg $ scp *.jpg tom@192.168.0.25:/home/tom/album_covers earth_wind_&_fire.jpg          100%    44KB  43.8KB/s handel_-_chamber_music.jpg     100%    12KB  12.3KB/s smiths_best_1.jpg              100%    47KB  47.5KB/s strokes_-_is_this_it.jpg       100%    38KB  38.3KB/s u2_pop.jpg                     100%   9222 9.0KB/sQ 


Now let's say you want to go the other direction. You're still on pound, and you want to copy several pictures of Libby from eliot to pound, and into a different directory than the one in which you currently are in:

$ scp tom@192.168.0.25:/home/tom/pictures/dog/libby* ~/pix/libby libby_in_window_1.20020611.jpg 100%  172KB 172.4KB/s libby_in_window_2.20020611.jpg 100%  181KB 180.8KB/s libby_in_window_3.20020611.jpg 100%  197KB 196.7KB/s libby_in_window_4.20020611.jpg 100%  188KB 187.9KB/s 


The scp command is really useful when you need to securely copy files between machines. If you have many files to copy, however, you'll find that scp can quickly grow tiresome. In cases like that, you might want to look at SFTP or a mounted Samba share (which is covered in "Mount a Samba Filesystem," found in Chapter 16, "Windows Networking").



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net