Mastering scp: Essential Commands, Options, and Real‑World Examples
This guide explains the scp command syntax, demonstrates how to use common options such as -v, -p, -C, -c, -l, -P, -r, and -q, and shows how to configure proxy settings and custom ssh_config files for secure and efficient file transfers.
Basic Syntax
The basic scp command copies a file from the local host to a remote host using the format:
scp source_file_name username@destination_host:destination_folderVerbose Output (-v)
Adding -v prints detailed debugging information, which helps diagnose connection, authentication, and configuration problems.
rumenz@local $ scp -v Label.pdf [email protected]:.
Executing: program /usr/bin/ssh host 192.168.1.110, user rumenz, command scp -v -t .
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012
... (debug output) ...
Label.pdf 100% 3672KB 136.0KB/s 00:27Preserve Timestamps and Modes (-p)
The -p flag preserves the original file’s modification time, access time, and mode.
rumenz@local $ scp -p Label.pdf [email protected]:.
Label.pdf 100% 3672KB 126.6KB/s 00:29Enable Compression (-C)
Using -C compresses data during transfer, which can speed up copying large files over the network. Compression is performed only on the wire; the file is restored to its original size on the destination.
rumenz@local $ scp -Cpv messages.log [email protected]:.
... (debug output) ...
messages.log 100% 93MB 602.7KB/s 02:38
debug1: compress outgoing: raw data 97571111, compressed 8806191, factor 0.09Change Encryption Cipher (-c)
By default scp uses AES‑128. To use a different cipher, such as 3DES, specify the -c option.
rumenz@local $ scp -c 3des Label.pdf [email protected]:.
Label.pdf 100% 3672KB 282.5KB/s 00:13Limit Bandwidth (-l)
The -l option limits bandwidth usage in kilobytes per second. For example, to cap the transfer at roughly 50 KB/s, set -l 400 (since scp’s unit is KB/s and 1 KB = 8 Kb).
rumenz@local $ scp -l 400 Label.pdf [email protected]:.
Label.pdf 100% 3672KB 50.3KB/s 01:13Specify a Non‑Standard Port (-P)
scp uses port 22 by default. To connect to a different SSH port, use -P followed by the port number.
rumenz@local $ scp -P 2249 Label.pdf [email protected]:.
Label.pdf 100% 3672KB 262.3KB/s 00:14Recursive Copy (-r)
To copy an entire directory and its contents, add the -r flag.
rumenz@local $ scp -r documents [email protected]:.
... (transfer output) ...
scp.txt 100% 10KB 9.8KB/s 00:00After completion, a documents directory containing all files appears on the remote host.
Suppress Progress and Messages (-q)
The -q option disables progress meters and diagnostic messages, leaving only the password prompt and the final shell prompt.
rumenz@local $ scp -q Label.pdf [email protected]:.
... (no progress output) ...
rumenz@local $Using a Proxy
When a network requires a proxy, scp itself cannot be configured directly. Instead, create an ~/.ssh/config entry that uses ProxyCommand with a tool like corkscrew:
ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p ~/.ssh/proxyauthStore the proxy credentials in ~/.ssh/proxyauth (format username:password) and ensure the file is readable only by the user.
Install corkscrew with:
# apt-get install corkscrew # Debian/Ubuntu
# yum install corkscrew # CentOSSelecting a Different ssh_config File (-F)
For users who frequently switch between corporate and public networks, maintain separate ssh configuration files and specify which one to use with -F: scp -F /home/pungki/proxy_ssh_config Label.pdf The default configuration resides in ~/.ssh/config. Using -F allows quick switching without editing the default file each time.
Additional Tips
Compression ( -C) is ineffective on already compressed files such as .zip, .rar, images, or .iso.
Bandwidth limits are expressed in kilobytes per second; calculate the desired limit accordingly.
Combine options as needed (e.g., scp -Cpv for compressed, verbose, and preserving timestamps).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
