scp
Securely copy files between computers
TLDR
Copy a local file to a remote host
Use a specific port when connecting to the remote host
Copy a file from a remote host to a local directory
Recursively copy the contents of a directory from a remote host to a local directory
Copy a file between two remote hosts transferring through the local host
Use a specific username when connecting to the remote host
Use a specific SSH private key for authentication with the remote host
Use a specific proxy when connecting to the remote host
SYNOPSIS
scp [options] [[user@]host1:]file1 [[user@]host2:]file2
scp [options] [[user@]host:]source_file [[user@]host:]destination_directory
scp [options] source_file1 source_file2 [[user@]host:]destination_directory
PARAMETERS
-P
Specifies the port to connect on the remote host. Note the uppercase 'P' for port.
-r
Recursively copy entire directories and their contents.
-p
Preserves modification times, access times, and modes of the source file(s).
-q
Enables quiet mode, suppressing the progress meter and non-error messages.
-v
Enables verbose mode, printing debugging messages about the connection and transfer.
-C
Enables compression during the transfer.
-i
Selects a file from which the identity (private key) for public key authentication is read.
-o
Can be used to pass options directly to the underlying SSH client.
-l
Limits the bandwidth used, specified in Kilobits per second (Kbit/s).
-B
Enables batch mode, preventing any interactive questions or prompts (e.g., for passwords).
DESCRIPTION
scp (secure copy) is a command-line utility that allows you to securely copy files and directories between local and remote hosts, or between two remote hosts. It utilizes the Secure Shell (SSH) protocol for data transfer, ensuring that the data is encrypted during transit and that authentication is secure. This makes scp a reliable method for transferring sensitive information over unsecured networks. It supports various authentication methods, including password-based and public-key authentication, inherited from SSH. scp is widely used for simple, one-time file transfers due to its straightforward syntax and integration with existing SSH infrastructure. While newer tools like rsync and sftp offer more advanced features (e.g., resuming transfers, incremental copies), scp remains a fundamental tool for many system administrators and developers.
CAVEATS
scp does not inherently support resuming interrupted transfers, meaning large file transfers might need to be restarted from scratch if the connection drops.
When copying files directly between two remote hosts (e.g., `host1:file host2:file`), the data typically traverses through the local machine where the scp command is executed, which can be inefficient for very large files or high-latency connections. For more advanced features like incremental transfers, resuming, or better handling of large directory structures, tools like rsync or sftp are generally recommended. Recent versions of OpenSSH have also shifted focus towards recommending sftp or rsync over scp due to scp's limited feature set and security considerations with parsing paths.
AUTHENTICATION
scp relies on SSH for authentication, supporting various methods including password-based authentication, public-key authentication (using SSH keys), and other methods configured for SSH.
DATA FLOW FOR REMOTE-TO-REMOTE
When copying files between two remote hosts (e.g., `host1:file host2:file`), the data typically flows through the local machine where the scp command is initiated. This means the local machine acts as an intermediary, downloading from the source and uploading to the destination, which might impact performance on high-latency networks.
HISTORY
scp originated as the secure counterpart to the older, insecure rcp (remote copy) command, leveraging the robust security features of the Secure Shell (SSH) protocol. It became an integral part of the OpenSSH suite, widely adopted as the standard for secure file transfers over networks. While its core functionality remained consistent for many years, recent developments in OpenSSH (starting around version 8.0) have transitioned scp to use an sftp backend by default. This change aims to improve scp's reliability and security by utilizing the more structured SFTP protocol for data transfer and path handling, though it may introduce subtle behavioral changes for some edge cases.
SEE ALSO
ssh(1), sftp(1), rsync(1), ssh-keygen(1)