You’d like to be able to automatically log out inactive users, especially root.
Set the $TMOUT environment variable in /etc/bashrc or ~/.bashrc to the number of seconds of inactivity before ending the session.
In interactive mode, once a prompt is issued, if the user does not enter a command in $TMOUT seconds, bash will exit.
$TMOUT is also used in the read built-in and the select command in scripts.
Don’t forget to set this as a read-only variable in a system-level file such as /etc/profile or /etc/bashrc to which users have no write access if you don’t want them to be able to change it.
declare -r TMOUT=3600