Stop SSH connection from freezing
On the client machine in
/etc/ssh/ssh_config add the following:
Host * ServerAliveInterval 100
ServerAliveInterval: The client will send a null packet to the server every 100 seconds to keep the connection alive
NULL packet: This is sent by the server to the client. The same packet is sent by the client to the server. A TCP NULL packet does not contain any controlling flag like SYN, ACK, FIN etc. because the server does not require a reply from the client.
On the server in
/etc/ssh/sshd_config add the following:
1 2 3
ClientAliveInterval 60 TCPKeepAlive yes ClientAliveCountMax 10000
ClientAliveInterval: The server will wait 60 seconds before sending a null packet to the client to keep the connection alive
TCPKeepAlive: This Is there to ensure that certain firewalls don't drop idle connections.
ClientAliveCountMax: Server will send alive messages to the client even though it has not received any message back from the client.
Depending on the machine, restart the ssh process
service sshd restart
service ssh restart
Stop the Service -
sudo launchctl stop com.openssh.sshd
Start the Service -
sudo launchctl start com.openssh.sshd
~/.ssh/config and add the config given below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Host webserver HostName 18.104.22.168 User root Host website HostName site.example.com User user Host site2 HostName 22.214.171.124 User root Port 2233 Host ubuntu HostName 192.168.225.50 User root IdentityFIle ~/.ssh/key_name
After adding the config, you could ssh into the respective server by using