Operations 11 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering scp: Essential Commands, Options, and Real‑World Examples

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_folder

Verbose 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:27

Preserve 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:29

Enable 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.09

Change 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:13

Limit 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:13

Specify 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:14

Recursive 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:00

After 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/proxyauth

Store 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       # CentOS

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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

networkLinuxcommand-linefile transferscp
Liangxu Linux
Written by

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

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.