4 Ways to Speed Up SSH Connections in Linux

If you use Linux for remote access to other servers or devices, you are likely familiar with SSH (Secure Shell) protocol. SSH is a network protocol that enables secure data communication over an unsecured network. However, sometimes SSH connections can be slow, and that can be frustrating. In this article, we will look at four key ways to speed up SSH connections in Linux.

Use Compression

Compression reduces the size of data transmitted over the network, which can significantly improve SSH connection speed, especially over slow or high-latency networks. To enable compression, add the following line to your SSH configuration file (~/.ssh/config)

Compression yes

This line tells SSH to enable compression for all data sent over the network. You can also set the compression level by adding

CompressionLevel 9

The compression level ranges from 1 to 9, with 1 being fastest and 9 being slowest but most efficient. You can experiment with different compression levels to find the one that works best for your network.

Use ControlMaster

ControlMaster is a feature that allows you to reuse an existing SSH connection to speed up subsequent connections. When enabled, SSH sets up a single master connection to the remote host and uses that connection for all subsequent connections to the same host.

To enable ControlMaster, add the following lines to your SSH configuration file

ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p

The first line tells SSH to use ControlMaster for all connections, and the second line specifies the path to the control socket. Make sure the ~/.ssh/sockets/ directory exists before using this configuration.

Once enabled, SSH will reuse the master connection for subsequent connections to the same host, which can significantly reduce connection establishment time.

Use a Faster Cipher

A cipher is a method of encrypting data transmitted over the network. SSH supports several ciphers, but some are faster than others. By using optimized ciphers, you can improve SSH connection speed without compromising security.

To specify faster ciphers, add the following line to your SSH configuration file

Ciphers aes128-ctr,aes192-ctr,aes256-ctr

This line specifies three fast and secure ciphers. The aes*-ctr ciphers are generally faster than other encryption methods while maintaining strong security.

Use Connection Multiplexing

Connection multiplexing allows you to reuse an existing SSH connection for multiple sessions. This eliminates the overhead of establishing new connections for each SSH session to the same host.

To enable multiplexing, add the following lines to your SSH configuration file

ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600

The ControlPersist 600 option keeps the master connection alive for 10 minutes (600 seconds) after the last session ends. This allows quick reconnections without re-establishing the connection.

Additional Optimization Tips

SSH Agent Forwarding

SSH agent forwarding allows you to use your local SSH agent to authenticate to remote servers, eliminating the need to enter passwords repeatedly. Add these lines to your SSH configuration

Host *
    ForwardAgent yes

Then connect using

ssh -A username@hostname

Disable DNS Lookups

To prevent DNS resolution delays, add this to your SSH configuration

GSSAPIAuthentication no
UseDNS no

Complete SSH Configuration Example

Here's a complete ~/.ssh/config file combining all optimizations

Host *
    Compression yes
    CompressionLevel 6
    ControlMaster auto
    ControlPath ~/.ssh/sockets/%r@%h-%p
    ControlPersist 600
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr
    ForwardAgent yes
    GSSAPIAuthentication no
    UseDNS no

Remember to create the sockets directory

mkdir -p ~/.ssh/sockets

Conclusion

These SSH optimization techniques can significantly improve connection speed and reduce latency. Compression reduces data size, ControlMaster reuses connections, faster ciphers improve encryption performance, and multiplexing eliminates connection overhead. Experiment with these settings to find the optimal configuration for your specific network environment and usage patterns.

Updated on: 2026-03-17T09:01:38+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements