HMC Homepage      CS Home

How to Securely Copy Files Between Machines: Using scp

There are several different Unix machines here at Harvey Mudd, and on occasion you will want to transfer files between them. This is traditionally done using ftp(1) or rcp(1); however, these are insecure as not only your file, but also your password are sent unencrypted over the network and could be intercepted. In fact, fear of this has caused ftp to be disabled on turing and other machines. Instead, you can use scp(1), which is secure.

Usage

scp acts a lot like cp(1), except that the file to copy and/or the destination can be prefixed with the name of a machine (followed by a colon). So, to get your homework from odin to turing, you might do:

odin % scp hw5.java turing.cs.hmc.edu:~

This copies hw5.java from the current directory on odin to your home directory (which is indicated by the ~  ) on turing. You will be prompted for your turing password. A status indicator is also displayed, but it won't mean much unless the file is quite large.

You can also go the other way:

turing % scp odin.ac.hmc.edu:~/hw5.java .

This accomplishes the same thing, but from turing's end.

Other options

  • If your username on the remote machine is different from your username on the local machine, prefix username@ to the name of the remote machine. Example:

    odin % scp hw5.java minime@turing.cs.hmc.edu:~

    (Assuming your username on turing is minime.)

  • If you see an error message like the following:

    Executing /usr/local/bin/ssh1 for ssh1 compatibility.
    command-line line 0: Bad configuration option.
    Connection lost.
    

    You should use the -1 option to scp. (Note: that 1 is the number "one".) Example:

    turing % scp -1 odin.ac.hmc.edu:~/hw5.java .

    The error indicates that the other machine is using a different version of the ssh protocol, on which scp is based. scp is supposed to automatically fall back to version 1 (which all of HMC's Unix machines should support) when this happens, but for some reason it doesn't work, so you have to do it manually with -1.

  • Several other options are given in the scp(1) man page (type man scp). See this if you want to do something not explained here.

  • NOTE: There is a very subtle error in scp that one should watch out for. This is really only for the really technical user but you might encounter it none the less. The problem is that scp sources the .cshrc file on the server machine when logging in to transfer files. Scp will take any output from commands run in this file and send it back as part of the file. This will confuse scp and it will barf with weird errors. The normal user shouldn't have to worry about this because none of the commands in the standard .cshrc file send any output to the screen. If you do modify your .cshrc, however, and then run into errors this is probably the problem. If this does appear to be the problem then send whatever text you want to see to stderr instead of stdout. This should fix the problem.


Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Wednesday, 25-Jul-2001 15:47:17 PDT