Open sshd_config using vim:
vim /etc/ssh/sshd_config
Add lines:
ClientAliveInterval 60 ClientAliveCountMax 720
And then apply changes by restarting sshd;
sudo /etc/init.d/ssh restart---
ClientAliveInterval configures the server to send null packets to clients every 60 seconds and ClientAliveCountMax configures the server to close the connection if the client has been inactive for 720 intervals that are 60*720 = 43200 which equals 12 hours.