Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling SSH Timeout When Connecting to/from Ubuntu 18.04

I used putty on windows to connect ssh to my droplet of Digitaloccean, but ssh session will expire after a short inactivity. What configuration I need to prolong the session timeout?

like image 555
Dung Avatar asked Nov 03 '25 04:11

Dung


2 Answers

There are 2 places you need to set configuration for: TESTED WORKING

Client config:

-Open file /etc/ssh/ssh_config and set directive ServerAliveInterval to a value like 100 for example:

# other configs
ServerAliveInterval 100

This causes your SSH client to send keep-alive messages every 100 seconds so that the server doesn't drop your connection.

Server config

-Open file /etc/ssh/sshd_config and add these configurations at the end of the file to ensure they're not overriden by later lines:

# other configs
ClientAliveInterval 600
TCPKeepAlive yes
ClientAliveCountMax 10

These are conservative settings that will make your SSH Server only disconnect after (600 * 10 = 6000) seconds of user inactivity. Customize these if you need more.

Restart the ssh server so that changes take effect:

$ sudo /etc/init.d/ssh restart

Source: http://queirozf.com/entries/disabling-ssh-timeout-when-connecting-to-from-ubuntu

like image 191
Dung Avatar answered Nov 04 '25 20:11

Dung


To prevent all your clients from timing out you need to edit /etc/sshd_config which is the server-side configuration file add these two options:

ClientAliveInterval 120
ClientAliveCountMax 720

The first one configures the server to send null packets to clients every 120 seconds and the second one configures the server to close the connection if the client has been inactive for 720 intervals that are 720*120 = 86400 seconds = 24 hours

like image 45
mohammadreza khalifeh Avatar answered Nov 04 '25 20:11

mohammadreza khalifeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!