SysTutorials

Controlling SCP Bandwidth with the -l Flag

The scp command supports bandwidth limiting through the -l flag, which caps the transfer rate in Kbit/s. This prevents large file transfers from saturating your network connection.

Basic Usage

The -l flag specifies the maximum bandwidth in kilobits per second (Kbit/s):

# Limit to 1000 Kbit/s (approximately 125 KB/s)
scp -l 1000 largefile.tar.gz user@remote:/path/to/destination/

# Limit to 500 Kbit/s (approximately 62 KB/s)
scp -l 500 user@remote:/path/to/file ./

Important: The value is in kilobits (Kbit/s), not kilobytes (KB/s). To convert:

Practical Examples

Don’t saturate a shared office connection:

scp -l 4000 backup.tar.gz server:/backups/

This limits transfers to about 500 KB/s — enough for the transfer to complete while leaving bandwidth for other users.

Transfer large files overnight without impacting daytime usage:

# Use with nohup for unattended transfers
nohup scp -l 2000 dataset.iso server:/data/ &

Keep an interactive SSH session responsive during transfer:

scp -l 8000 bigfile user@host:/tmp/

Limitations of scp -l

The -l flag has several limitations:

Alternative: rsync with Bandwidth Limiting

rsync provides more precise bandwidth control and is generally preferred over SCP:

# rsync uses KB/s (not Kbit/s like scp)
rsync -avz --progress --bwlimit=500 largefile user@remote:/path/

# --bwlimit=500 means 500 KB/s (compare to scp -l 4000 for similar speed)
rsync -avz --bwlimit=1000 --partial --progress ./data/ user@remote:/backup/data/

Advantages of rsync over scp:

Alternative: trickle for Any Command

trickle is a userspace bandwidth shaper that works with any TCP application:

sudo apt install trickle    # Ubuntu/Debian
sudo dnf install trickle    # Fedora

# Limit scp to 100 KB/s download, 100 KB/s upload
trickle -d 100 -u 100 scp file user@host:/path/

# Limit wget
trickle -d 200 wget http://example.com/largefile

Trickle works by intercepting socket calls, so it works with any program that uses TCP.

Network-Level Bandwidth Control

For system-wide bandwidth management, use Linux traffic control:

# Limit all outgoing SSH traffic to 1 Mbps
sudo tc qdisc add dev eth0 root handle 1: htb default 10
sudo tc class add dev eth0 parent 1: classid 1:10 htb rate 1mbit

# Remove the rule
sudo tc qdisc del dev eth0 root

This approach is useful when you want to limit all SSH transfers system-wide rather than per-command.

Quick Reference

For most use cases, rsync --bwlimit is the best choice — it’s more precise, supports resume, and uses a more intuitive unit (KB/s).

← All posts