Accelerate SSH connections in ansible
Today I show a much easier, more comprehensible and even faster method with SSH proxyjump in your settings via config file and SSH multiplexing.
SSH multiplexing
With the multiplexing feature, SSH connections can be accelerated significantly.
SSH multplexing minimizes the overhead of TCP connection and key negotiation. Connections are not constantly being rebuilt.
To enable the feature, you need the following entry in your local ~/.ssh/config on your control node:
- %r is the remote user
- %h is the remote host
- %p is the remote port
Multiplexing uses sockets that are stored in the /tmp directory.
However, you can basically use any other path in which the user is allowed to write.
In order for ansible to be able to use the acceleration, enter the following in your targets hosts config file:
You can also make this setting centrally in ansible.cfg for all target nodes. The entry would be here:
SSH Proxyjump
If, like me, you can't remember the many SSH proxyjump commands, you can help yourself by using the SSH config.
In ~/.ssh/config there is the possibility to enter hosts and to configure the proxyjump command easily understandable as default for the connection to server X.
To do this, first enter the gateway server:
All other hosts can be entered below:
Connection via SSH can now be executed without complex SSH command. In this case it would be:
ssh targethost
The target node can now be entered accordingly in the inventory list.