The Vanishing Session
When managing an Ubuntu server via SSH or working in a local TTY terminal (accessed via Ctrl+Alt+F3), security is paramount. To prevent unauthorized access if you walk away from your keyboard, the system may utilize an environment variable called `TMOUT`. If this variable is set, the bash shell constantly monitors your keystrokes. If a specific number of seconds pass without any input (e.g., 300 seconds for 5 minutes), the shell automatically terminates the session, logging you out and closing the terminal. While secure, this is infuriating if you are simply reading a long log file output and the terminal abruptly closes on you.
Disabling the Timeout
To maintain your active sessions indefinitely and stop Ubuntu from automatically closing inactive terminals due to timeouts, you must remove or unset the `TMOUT` variable from your bash profile.
First, check if the timeout is active by opening your terminal and typing: echo $TMOUT. If it returns a number (like 300 or 600), the timeout is active. To disable it for the current session only, simply type: unset TMOUT. To disable it permanently, you must edit your user profile. Type: nano ~/.bashrc. Scroll to the very bottom of the file and look for a line that says `export TMOUT=…` or `readonly TMOUT=…`. Delete that entire line, or comment it out by placing a `#` at the beginning of the line. If you do not see it there, check the system-wide profile by typing: sudo nano /etc/profile. Once you have removed or commented out the variable, press Ctrl+O to save and Ctrl+X to exit. The change will take effect the next time you log in.