CentOS 8.x SSH client tips and tricks
Home > CentOS > CentOS 8.x > System Administration > SSH client > Tips and tricks
SSH connection multiplexing
We can configure SSH connection multiplexing for SSH client to use existing SSH connection for new SSH / rsync / scp commands. This has advantages such as:
- If the authentication is password based, then we do not need to enter password again for the additional sessions.
- Also since new connection (TCP/SSH) is not required for the second requirement, the connection gets established really fast.
To configure SSH connection multiplexing use: Create file /etc/ssh/ssh_config.d/10-ssh-connection-multiplexing.conf with
Host * ControlMaster auto ControlPath /tmp/%r@%h:%p
Note that sharing connections is property of SSH client and not SSH server.
ControlMaster also takes other parameters like yes, no apart from auto. But if we use yes or not we need to explicitly specify whether this is first connection (Master connection) or slave connection which is not convenient. Hence using auto saves us from having to specify yes or not appropriately for each connection.
Use of ssh ProxyCommand option in /etc/ssh/ssh_config or ~/.ssh/config configuration file
For this use configuration similar to:
Host machine2 ProxyCommand ssh root@machine1 nc machine2 22
Note that this configuration assumes package 'nc' is installed on machine1
- In this case we can directly connect to machine2 and use of machine1 as middle-man is transparent
- Since direct SSH handshake will happen between laptop and machine2, we do not need agent forwarding
- Copying of files from laptop to machine2 will also work directly (through machine1 as middle man)
[root@laptop ~]# ssh root@machine2 ... [root@machine2 ~]
Futher if SSH connection multiplexing using ControlMaster and ControlPath options is also configured (Explained at Sharing multiple ssh connections) then additional channels to machine2 will be much faster by use of same parent connection.
Steps learned from http://sshmenu.sourceforge.net/articles/transparent-mulithop.html
Close hung SSH connection
Sometimes SSH connection to remote host gets hung due to network issues (Eg close laptop lid without disconnection SSH session). In such cases we can terminate hung SSH session using shortcut "Enter -> ~ -> ."
Refer:
Check current SSH connection details
While connected to a remote server, if you want to check the parameters (Client IP, Client port, Server IP and server port) for current SSH connection use:
echo $SSH_CONNECTION
Prevent "client_loop: send disconnect: Broken pipe"
To avoid session getting disconnected when idle use:
Create file /etc/ssh/ssh_config.d/10-serveraliveinterval.conf with
Host * ServerAliveInterval 120
Home > CentOS > CentOS 8.x > System Administration > SSH client > Tips and tricks