When working with SSH, it's crucial to understand the protocol version you're using. You can check your current protocol version by running:
ssh -V
For modern systems, you'll typically see something like "OpenSSH_8.9p1" which indicates you're using protocol version 2 by default.
Unlike SSH Protocol 1 where you could specify CompressionLevel similar to gzip, Protocol 2 implements compression differently. The options are more limited but still effective for dial-up connections.
To maximize compression in SSH Protocol 2, create or modify your ~/.ssh/config file with these settings:
Host *
Compression yes
Ciphers aes128-ctr
MACs hmac-sha1
Protocol 2
ServerAliveInterval 60
TCPKeepAlive yes
If you need even better compression, consider these additional techniques:
# Using a compressed archive before transfer
tar czf - /path/to/files | ssh user@host "tar xzf -"
# For interactive sessions with maximum compression
ssh -C -c aes128-ctr user@host
To verify your compression effectiveness, you can use these commands:
# Before compression
du -sh /path/to/data
# After transfer with compression enabled
ssh -C user@host "du -sh /path/to/data"
For persistent connections, ensure your server's /etc/ssh/sshd_config contains:
Compression yes
ClientAliveInterval 60
TCPKeepAlive yes
Remember to restart sshd after changes:
sudo systemctl restart sshd
If you're not seeing expected compression results:
# Check active SSH sessions
ssh -vvv user@host
# Verify compression algorithm
grep -i compression /etc/ssh/ssh_config /etc/ssh/sshd_config ~/.ssh/config
When working with SSH tunnels on limited bandwidth connections (like dial-up), compression becomes crucial. The man page clearly states that CompressionLevel
only applies to SSH Protocol Version 1. Here's how to identify and maximize compression in SSHv2:
# Check your SSH protocol version
ssh -V
# Sample output: OpenSSH_8.9p1, OpenSSL 3.0.7, protocol 2.0
While SSHv2 doesn't support compression levels like SSHv1, you can still enable compression with these methods:
# Basic compression enable
ssh -C user@host
# In your SSH config (~/.ssh/config):
Host *
Compression yes
CompressionLevel 9 # Note: This is ignored in SSHv2
For maximum compression in SSHv2, consider these approaches:
# Combine with other compression tools
tar czf - /path/to/files | ssh -C user@host "cat > backup.tar.gz"
# For persistent connections:
ssh -f -N -C -L 3306:localhost:3306 user@host
When SSH compression isn't sufficient:
- Use
mosh
(Mobile Shell) which handles poor connections better - Pre-compress data before transmission
- Consider VPN with LZO compression
Remember that compression:
- Increases CPU usage on both ends
- May not help with already compressed data (JPEGs, ZIP files)
- Can sometimes increase latency