Disable/Fix SSH Timeouts On Ubuntu Server

If you get even remotely as annoyed as I do when you recieve an SSH timeout or disconnect then this post is for you. Below is how to quickly and easily fix the SSH timeout issue on the server side. This solution will not disable the timeouts entirely though, instead it just sets the threshold extremely high. While you can fix ssh timeouts on your clients, its much better to do so on your server that way you won’t have to do it on every single client/computer that is used to connect to your server.

First lets make a copy of your current sshd_config file by running the following:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

Next lets open up the sshd_config file with vi, you can use nano or another text editor if you prefer:

sudo vi /etc/ssh/sshd_config

If you are not used to vi or any other terminal based text editor then I will try to make life easier for you in the next few steps. Press the “i” button on your keyboard to enter insert mode and then navigate with the arrow keys until you find the following lines:

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

Add the following information below to set the timeout settings to your sshd_config file. If any of these lines exist elsewhere in your configuration file you should delete them to prevent these lines from being overridden by the default settings.

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

TCPKeepAlive no
ClientAliveInterval 30
ClientAliveCountMax 240

Now that we have added the entries above to your ssh configuration file, save the changes by pressing the escape key (esc) and then entering “:wq” followed by pressing enter. Last but not least we will restart the ssh service so the changes can take effect. Your current ssh session will remain active and unchanged, but when you reconnect the changes will take effect.

sudo service sshd restart

Congratulations, your SSH timeout problems should be solved unless you leave your session untouched for around a day or so. Please don’t forget to like/comment/share! 🙂

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *