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:

Host *
    ControlMaster auto
    ControlPath /tmp/%r@%h:%p
~/.ssh/config
  • %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:

ansible_ssh_common_args='-o ControlMaster=auto -o ControlPersist=60s'
ansible config

You can also make this setting centrally in ansible.cfg for all target nodes. The entry would be here:

ssh_args = -o ControlMaster=auto -o ControlPersist=60s
ansible.cfg

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:

Host gateway
    HostName gateway_server_IP
    # Optional:
    # IdentityFile ~/.ssh/id_rsa
    User SSH_user
    Port 22
~/.ssh/config

All other hosts can be entered below:

Host targethost
    HostName targethost_IP_or_Hostname
    ProxyJump gateway
    # Optional:
    #IdentityFile ~/.ssh/id_rsa_targethost
    User SSH_user
    Port 22
~/.ssh/config

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.