SSH Compression and Performance Optimization
Optimize SSH connection performance with compression, cipher selection, and multiplexing. Improve speed for slow connections and reduce overhead for fast ones.
Detailed Explanation
SSH Performance Optimization
SSH performance can be tuned by adjusting compression, cipher selection, and connection multiplexing. The right settings depend on your network conditions and use case.
Compression Config
Host slow-connection
HostName remote.example.com
User developer
Compression yes
ServerAliveInterval 30
Host fast-connection
HostName nearby.example.com
User developer
Compression no
When to Use Compression
| Network | Compression | Why |
|---|---|---|
| Slow/high-latency | yes | Reduces data transferred |
| Fast LAN | no | CPU overhead exceeds bandwidth savings |
| Already compressed data | no | Re-compression adds CPU without benefit |
| Interactive sessions | yes (if slow link) | Reduces character echo delay |
| File transfers (scp/rsync) | depends | Helps for text, hurts for binaries |
Connection Multiplexing
Multiplexing reuses a single SSH connection for multiple sessions, eliminating the overhead of repeated handshakes:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
Create the socket directory first: mkdir -p ~/.ssh/sockets
| Directive | Purpose |
|---|---|
ControlMaster auto |
Automatically share connections |
ControlPath |
Socket file location (must be unique per host) |
ControlPersist 600 |
Keep master connection alive for 10 minutes |
Benefits of Multiplexing
- Instant new sessions (no TCP handshake or key exchange)
- Faster
scp,rsync, andgitoperations to the same host - Reduced load on the SSH server
Cipher Selection
For fastest performance on trusted networks:
Host trusted-lan
Ciphers aes128-gcm@openssh.com,chacha20-poly1305@openssh.com
aes128-gcm is fastest on hardware with AES-NI support (most modern CPUs). chacha20-poly1305 is fastest on systems without AES-NI (like some ARM devices).
Measuring Performance
Test SSH throughput with:
dd if=/dev/zero bs=1M count=100 | ssh host "cat > /dev/null"
Compare with different cipher and compression settings to find the optimal configuration for your link.
Use Case
Users who need to optimize SSH performance for slow network connections, frequent reconnections, or high-throughput file transfers between hosts.