Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Unix, how do I use SCP to securely transfer files between two computers?

In Unix, you can use SCP (the scp command) to securely copy files and directories between remote hosts without starting an FTP session or logging into the remote systems explicitly. The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication. Unlike rcp or FTP, scp encrypts both the file and any passwords exchanged so that anyone snooping on the network cannot view them.

Syntax

The syntax for the scp command is:

scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2

The location of the source file is specified by username1@source_host:directory1/filename1 , which includes the:

  • Name of the account on the host computer (username1)
  • Hostname of the computer on which the source file resides (source_host)
  • Name of the directory containing the source file (directory1)
  • Filename of the source file (filename1)

The location to which the source file will be copied is specified by username2@destination_host:directory2/filename2 , which includes the:

  • Name of the account on the destination computer (username2)
  • Hostname of the computer to which the source file will be copied (destination_host)
  • Name of the directory to which the source file will be copied (directory2)
  • Filename of the copy (filename2)

Note: Make sure to include a space between the source and destination paths. Also, be careful when copying files that share the same name on both hosts; you may accidently overwrite data you intended to keep.

For more about scp, consult its manual page. At the Unix prompt, enter:

man scp

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

Examples

For the following examples, assume your username is dvader, and you are logged into your account on the computer empire.gov :

  • To copy a file called rebels.txt from your home directory on empire.gov to a directory called revenge in your account on the computer deathstar.com , enter: scp ~/rebels.txt dvader@deathstar.com:~/revenge

    You'll be prompted for your password on the destination system (deathstar.com). The command won't work unless you enter the correct password.

  • To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents.

    To copy the entire revenge directory from your deathstar.com account to your empire.gov account, enter:

    scp -r dvader@deathstar.com:~/revenge ~/revenge

    You'll be prompted for your password on the source system (deathstar.com). The command won't work unless you enter the correct password.

  • To copy multiple files within a directory, you can use wildcards (e.g.,  *  or  ? ). However, to use wildcards for copying multiple source files from a remote system, you need to place quotes ( " " ) around the path to the source files. This is necessary because the Unix shell, not the scp command, expands unquoted wildcards.

    Therefore, to copy all the .txt files from the revenge directory on your deathstar.com account to your revenge directory on empire.gov, enter:

    scp dvader@deathstar.com:"revenge/*.txt" ~/revenge/

    You'll be prompted for your password on the source system (deathstar.com). The command won't work unless you enter the correct password.

For the following example, assume you (dvader) are logged into another computer (i.e., some other computer that's not empire.gov or deathstar.com). To copy luke.txt from your home directory on empire.gov to your revenge directory on deathstar.com, enter:

scp dvader@empire.gov:~/luke.txt dvader@deathstar.com:~/revenge

You'll be prompted to enter two passwords: one for the source system (empire.gov) and one for the destination system (deathstar.com). The command won't work unless you correctly enter both passwords.

This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.

This is document agye in domains all and xsede-all.
Last modified on December 12, 2012.

I need help with a computing problem

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.



Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

I have a comment for the Knowledge Base

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.