Your browser does not allow storing cookies. We recommend enabling them.

scp - Secure File Copy

scp is a program for copying files between computers. It uses the SSH protocol. It is included by default in most Linux and Unix distributions. It is also included in the [Tectia SSH}(/products/tectia-ssh/) and OpenSSH packages.

Basic usage

The basic usage of scp is as follows:

scp file host:path

This copies the file to the remote host. The destination path is optional, but can be a directory on the server, or even a file name if copying a single file. It is possible to specify multiple files; the last one is the destination.

To copy a file from the remote host, use:

scp host:file path

This fetches the file from the host, and puts it in the directory indicated by path. Often, path is just ., meaning the current working directory.

Copying directory trees with scp

To cpoy entire directory trees instead of single files, add the -r option. For example:

scp -r host:path/directory .

This would fetch path/directory from the host, copying it to the current working directory (creating directory in current working directory).

Configuring public key authentication

Normally, scp asks for a password. To avoid this, or to automate file copying in scripts, public key authentication is usually used.

The basic idea is to create a key pair on the client and copy the public key to the server into an authorized keys file. See how to set up public key authentication.

Don't forget to establish proper SSH key management pratices. See how to manage SSH keys.




What to read next:

  • Reduce Secure Shell risk. Get to know the NIST 7966.

    The NISTIR 7966 guideline from the Computer Security Division of NIST is a direct call to action for organizations regardless of industry and is a mandate for the US Federal government.
    Download now
  • ISACA Practitioner Guide for SSH

    With contributions from practitioners, specialists and SSH.COM experts, the ISACA “SSH: Practitioner Considerations” guide is vital best practice from the compliance and audit community.
    Download now