Timeout ssh sessions after inactivity?

Solution 1:

Could you put "exec screen -R" in .bash_profile and "idle 900 lockscreen" in .screenrc to solve this? That'd automatically reattach to their screen session if it's still there and create a new one if it isn't, but lock the screen if it's idle for 900 seconds.

I believe users could disable the idle, though...

Alternately: just plain "exec screen" and also "autodetach off" in .screenrc so that their sessions die if they get disconnected.

Solution 2:

The following, added to your sshd config, will simply close the SSH connection after 15 minutes of inactivity:

ClientAliveInterval 900
ClientAliveCountMax 0

It is essential to include ClientAliveCountMax 0 to prevent the server from sending "client alive messages" to the SSH client.

Solution 3:

Under BSD i'm using idled by Michael P. Crider

Quote from description

Idled is a daemon that runs on a machine to keep an eye on current users. If users have been idle for too long, or have been logged on for too long, or have logged in too many times, it will warn them and log them out appropriately.

I think you also can find it in linux repositories.