Skip to main content

4 Ways to Speed Up SSH Connections in Linux .

SSH is the most popular and secure method for managing Linux servers remotely. One of the challenges with remote server management is connection speeds, especially when it comes to session creation between the remote and local machines.

There are several bottlenecks to this process, one scenario is when you are connecting to a remote server for the first time; it normally takes a few seconds to establish a session. However, when you try to start multiple connections in succession, this causes an overhead (combination of excess or indirect computation time, memory, bandwidth, or other related resources to carry out the operation).

In this article, we will share four useful tips on how to speed up remote SSH connections in Linux.

1. Force SSH Connection Over IPV4

OpenSSH supports both IPv4/IP6, but at times IPv6 connections tend to be slower. So you can consider forcing ssh connections over IPv4 only, using the syntax below:

# ssh -4 username@example.com

Alternatively, use the AddressFamily(specifies the address family to use when connecting) directive in your ssh configuration file /etc/ssh/ssh_config (global configuration) or ~/.ssh/config (user specific file).

The accepted values are “any”, “inet” for IPv4 only, or “inet6”.

$ vi ~.ssh/config

Disable SSH Connections on ipv6

Here is a useful starter guide on configuring user specific ssh configuration file:

How to Configure Custom SSH Connections to Simplify Remote Access

Additionally, on the remote machine, you can also instruct the sshd daemon to consider connections over IPv4 by using the above directive in the /etc/ssh/sshd_config file.

2. Disable DNS Lookup On Remote Machine

By default, sshd daemon looks up the remote host name, and also checks that the resolved host name for the remote IP address maps back to the very same IP address. This can result into delays in connection establishment or session creation.

The UseDNS directive controls the above functionality; to disable it, search and uncomment it in the /etc/ssh/sshd_config file. If it’s not set, add it with the value no.

UseDNS no

Disable SSH DNS Lookup

3. Reuse SSH Connection

An ssh client program is used to establish connections to an sshd daemon accepting remote connections. You can reuse an already-established connection when creating a new ssh session and this can significantly speed up subsequent sessions.

You can enable this in your ~/.ssh/config file.

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

The above configuration (Host *) will enable connection re-use for all remote servers you connect to using these directives:

ControlMaster – enables the sharing of multiple sessions over a single network connection.ControlPath – defines a path to the control socket used for connection sharing.ControlPersist – if used together with ControlMaster, tells ssh to keep the master connection open in the background (waiting for future client connections) once the initial client connection has been closed.

Reuse SSH Connections

You can enable this for connections to a specific remote server, for instance:

Host server1 HostName www.example.com IdentityFile ~/.ssh/webserver.pem User username_here ControlMaster auto ControlPath ~/.ssh/sockets/%r@%h-%p ControlPersist 600

This way you only suffer the connection overhead for the first connection, and all subsequent connections will be much faster.

4. Use Specific SSH Authentication Method

Another way of speeding up ssh connections is to use a given authentication method for all ssh connections, and here we recommend configuring ssh passwordless login using ssh keygen in 5 easy steps.

Once that is done, use the PreferredAuthentications directive, within ssh_config files (global or user specific) above. This directive defines the order in which the client should try authentication methods (you can specify a command separated list to use more than one method).

PreferredAuthentications=publickey

SSH Authentication Method

Optionally, use this syntax below from the command line.

# ssh -o "PreferredAuthentications=publickey" username@example.com

If you prefer password authentication which is deemed unsecure, use this.

# ssh -o "PreferredAuthentications=password" username@example.com

Finally, you need to restart your sshd daemon after making all the above changes.

# systemctl restart sshd #Systemd # service sshd restart #SysVInit

For more information about the directives used here, see the ssh_config and sshd_config man pages.

# man ssh_config # man sshd_config

Comments

Popular posts from this blog

Hot Selling Frameless One-piece Jelly Color Transparent Sun Glasses

  Step out in style with our Cross-border Hot Selling Frameless One-piece Jelly Color Transparent Sun Glasses! Perfect for any occasion, these sunglasses are sure to turn heads. Get yours now at Josidel Online Stores with free shipping! Shop here: https://josidelonlinestores.com/product/cross-border-hot-selling-frameless-one-piece-jelly-color-transparent-sun-glasses/
  Looking for stylish and affordable sunglasses to elevate your look? Look no further than Josidel Online Stores! Our Men and Women Fashion Sports Retro Sunglasses are the perfect addition to any outfit. Whether you're lounging on the beach, taking a stroll in the park, or driving around town, our sunglasses provide both style and protection from the sun. Our sunglasses are crafted from high-quality materials and designed to last. The retro-inspired frame is perfect for those who love a vintage look, while the sports design ensures a comfortable and secure fit for any outdoor activity. The lenses are made from high-quality materials that provide superior UV protection, making them perfect for those sunny days when you want to look your best. At Josidel Online Stores, we pride ourselves on providing the best customer service and products. We offer fast and reliable shipping, so you can start enjoying your new sunglasses as soon as possible. Our prices are competitive, and we always ...

Women's Fashion Butterfly Cuban Necklace

 Looking for the perfect accessory to add some sparkle to your outfit? Check out our Women's Fashion Butterfly Cuban Necklace, available now at Josidel Online Stores . Crafted with exquisite attention to detail, this necklace features a delicate butterfly pendant that hangs gracefully from a classic Cuban chain. Made with high-quality materials, it is durable and long-lasting, making it perfect for everyday wear or special occasions. The Cuban chain adds a touch of sophistication to the necklace and complements the butterfly pendant beautifully, making it the perfect statement piece to wear with any outfit. Whether you're dressing up for a night out or dressing down for a casual day, this necklace is the perfect addition to any look. At Josidel Online Stores , we are committed to providing our customers with the best quality products at affordable prices. That's why we offer free shipping on all our products, including this Women's Fashion Butterfly Cuban Necklace . Don...