Request demo

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 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).

ssh tunneling, secure remote access, SSH

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 practices. See how to manage SSH keys.