To prevent disconnections on client side in your SSH terminal you can add this parameter to the configuration file /etc/ssh/ssh_config:
Basically this option will send a null packet to the remote host every 100 seconds and will keep alive the connection.
To generate the pair public/private keys type on the shell:
~ $ ssh-keygen -t rsa -b 2048
It ask you for a pass-phrase, it’s important choose a stronge pass-phrase, letters, numbers, symbols etc. If you accept the default path and name for the key it will create two files, the private key, id_rsa, and the public key, id_rsa.pub, in .ssh folder at your HOME:
Check permissions, 600 for files and 700 for the .ssh directory.
Now just copy the content of id_rsa.pub and add it to the user home know_hosts file, on the server you want to connect you:
~ $ cat id_rsa.pub >> /root/.ssh/know_hosts
Finally add the private key identity to the authentication agent:
~ $ ssh-add
It will ask you for the pass-phrase, type it. By this way the identity will be stored and now when you try to connect to the server with the public key, you will enter safely without password:
~ $ ssh root@server