How to Stop Ubuntu from Automatically Closing Inactive Terminals

The Terminal Timeout

For system administrators and developers using Ubuntu Linux, the GNOME Terminal is the most critical tool on the desktop. Often, you might have several terminal windows open, each running a long background process, monitoring a log file (using `tail`), or maintaining an SSH connection to a remote server. In some specific enterprise configurations or when using aggressive power-saving tools (like TLP), Ubuntu might be configured to automatically close or suspend inactive terminal sessions after a certain period to save resources or for security purposes. Finding your critical SSH session silently terminated because you did not type anything for 30 minutes is incredibly frustrating.

Disabling Session Timeouts

To ensure your long-running tasks survive and stop Ubuntu from automatically closing inactive terminal windows, you must check both the terminal profile settings and the system-wide environment variables.

First, open your GNOME Terminal. Click the hamburger menu (three horizontal lines) in the top-right corner and select Preferences. Click on your current profile (usually “Unnamed” or “Default”) on the left side. Go to the Command tab. Ensure that “When command exits” is set to “Hold the terminal open.” However, if the terminal is closing due to an idle timeout, you need to check your shell configuration. Open a terminal and edit your bash profile by typing nano ~/.bashrc. Scroll to the bottom of the file and look for a variable called TMOUT. If you see a line like TMOUT=1800 (which means 30 minutes), delete that line or change it to TMOUT=0 (which disables the timeout). Save the file (Ctrl+O, Enter, Ctrl+X) and restart your terminal.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.