The SCP is a network protocol, based on the BSD RCP protocol,5 which supports file transfers between hosts on a network. SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data in transit. A client can send (upload) files to a server, optionally including their basic attributes (permissions, timestamps). Clients can also request files or directories from a server (download). SCP runs over TCP port 22 by default.6 Like RCP, there is no RFC that defines the specifics of the protocol.
Normally, a client initiates an SSH connection to the remote host, and requests an SCP process to be started on the remote server. The remote SCP process can operate in one of two modes:
For most SCP clients, source mode is generally triggered with the -f flag (from), while sink mode is triggered with -t (to).7 These flags are used internally and are not documented outside the SCP source code.
In the past, in remote-to-remote secure copy, the SCP client would open an SSH connection to the source host and request that it, in turn, open an SCP connection to the destination. (Remote-to-remote mode did not support opening two SCP connections and using the originating client as an intermediary). SCP thus could not be used to remotely copy from the source to the destination when operating in password or keyboard-interactive authentication mode, as this would reveal the destination server's authentication credentials to the source. It was, however, possible with key-based or GSSAPI methods that do not require user input.8
More recently, remote-to-remote mode supports routing traffic through the client which originated the transfer, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the originating client, the 3rd party.9
SCP does not expect text communicating with the SSH login shell. Text transmitted due to the SSH profile (e.g. echo "Welcome" in the .bashrc file) is interpreted as an error message, and a null line (echo "") causes SCP client to deadlock waiting for the error message to complete.10
The SCP program11 is a software tool implementing the SCP protocol as a service daemon or client. It is a program to perform secure copying.
Perhaps the most widely used SCP program is the OpenSSH command line scp program, which is provided in most SSH implementations. The scp program is the secure analog of the rcp command. The scp program must be part of all SSH servers that want to provide SCP service, as scp functions as SCP server too. Since OpenSSH 9.0, the program has been updated to use the newer, more secure SFTP protocol; an -O option is added for using SCP with old SCP-only servers.12
Typically, a syntax of scp program13 is like the syntax of cp (copy):
Copying local file to a remote host:
Copying file from remote host and recursively copying folder (with -r switch) from remote host:
Note that if the remote host uses a port other than the default of 22, it can be specified in the command. For example, copying a file from host:
As the Secure Copy Protocol implements file transfers only, GUI SCP clients are rare, as implementing it requires additional functionality (directory listing at least). For example, WinSCP defaults to the SFTP protocol.14 Even when operating in SCP mode, clients like WinSCP are typically not pure SCP clients, as they must use other means to implement the additional functionality (like the ls command).15 This in turn brings platform-dependency problems.
More comprehensive tools for managing files over SSH are SFTP clients.
In 2019 vulnerability CVE-2019-611116 was announced related to the openssh SCP tool and protocol allowing users to overwrite arbitrary files in the SCP client target directory.
"Linux and Unix scp command". Computer Hope. Retrieved 4 August 2015. https://www.computerhope.com/unix/scp.htm ↩
Pechanec, Jan. "How the SCP protocol works". Jan Pechanec's weblog. Oracle. Archived from the original on 2017-02-15. Retrieved 4 August 2015. /w/index.php?title=Jan_Pechanec&action=edit&redlink=1 ↩
"OpenSSH 8.0". OpenSSH Release Notes. 17 April 2019. https://www.openssh.com/txt/release-8.0 ↩
"OpenSSH 9.0". OpenSSH Release Notes. 8 April 2022. https://www.openssh.com/txt/release-9.0 ↩
"scp(1) - OpenBSD manual pages (history section)". Retrieved 25 June 2012. https://man.openbsd.org/scp#HISTORY ↩
"SCP - Secure Copy Protocol - What is it & Full Definition & Example Cmds!". PC & Network Downloads - PCWDLD.com. 2019-06-29. Retrieved 2020-05-22. https://www.pcwdld.com/what-is-scp ↩
Carroll, Brandon (16 August 2017). "How to use Secure Copy for file transfer". TechRepublic. Retrieved 2020-05-22. https://www.techrepublic.com/article/how-to-use-secure-copy-for-file-transfer/ ↩
"Portable OpenSSH". GitHub. 13 May 2022. https://github.com/openssh/openssh-portable/blob/master/scp.c ↩
"scp(1) - OpenBSD manual pages" https://man.openbsd.org/scp https://man.openbsd.org/scp ↩
"Supported File Transfer Protocols :: WinSCP". winscp.net. Retrieved 2020-05-22. https://winscp.net/eng/docs/protocols ↩
"The SCP/Shell Page (Advanced Site Settings dialog) :: WinSCP". winscp.net. Retrieved 2020-05-22. https://winscp.net/eng/docs/ui_login_scp ↩
"NVD - Cve-2019-6111". https://nvd.nist.gov/vuln/detail/CVE-2019-6111 ↩