Fix "Putty session keeps disconnecting when idle"

I was facing this issue on most of my machines where the putty terminal was getting disconnected when it was left idle for few minutes so every time I had to log in back to work on the terminal.
Error:
Putty session disconnects when left idle for few minutes
Cause:
# vi /etc/ssh/sshd_config 
ClientAliveInterval 0
ClientAliveCountMax 3

By default these values are set to 0

Let me explain what is the meaning of the above parameters
ClientAliveInterval:

Sets a timeout interval in seconds after which if no data has been received from the client, sshd will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.
ClientAliveCountMax:
Sets the number of client alive messages which may be sent without receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session.

Solution:

# vi /etc/ssh/sshd_config 
ClientAliveInterval 60
ClientAliveCountMax 5

Add this line as shown in the following file

# vi /etc/ssh/ssh_config
ServerAliveInterval 60

Create a file at this location if it does not exist

# vi /root/.ssh/config
Host *
ServerAliveInterval 60

NOTE: Make sure you give a space before ServerAliveInternal as shown above

# service sshd restart

So now every 60 seconds ssh client will send a message through encrypted channel to the server so that the session does not disconnects when left idle.

And the default threshold value for the messages to be received is 5 which means that the client to server session can tolerate or skip 5 messages before it disconnects the session.

Next time when you do ssh to any client use the following command:
# ssh -vvv "client IP or hostname"