The error message bash: TMOUT: readonly variable indicates that the TMOUT variable has been set as readonly, which prevents you from changing its value in your current session.
This is usually done for security reasons, often in a global configuration file, to enforce automatic logouts for idle sessions.
To fix this and change the TMOUT value, you need to locate where it has been set as readonly and modify it there.
Table of Contents
Steps to Fix TMOUT: readonly variable Error
Follow these steps to address this issue:
1. Check Global Configuration Files
Look for the TMOUT setting in global shell configuration files such as /etc/profile, /etc/bash.bashrc, or /etc/profile.d/. Use grep -r TMOUT /etc/ to aid in searching.
2. Modify the Configuration
Once you’ve located the file where TMOUT is set:
- Open the file with a text editor, such as nano or vim. You will likely need sudo privileges: sudo nano /etc/profile, for example.
- Look for a line like readonly TMOUT or export TMOUT and declare -r TMOUT.
- Modify or remove the readonly attribute as needed. If you just want to change the value of TMOUT, adjust the value in the export TMOUT=<value> line.
- Save the file and exit the editor.
3. Reload the Shell
After changes, either log out and back in, or source the global file with source /etc/profile.
4. Check for Script-Enforced Read-Only
If not found in global files, check personal files like ~/.bashrc or ~/.bash_profile for TMOUT settings.
Caution
- Altering global configuration files affects all users on the system. It’s important to understand the implications of these changes, especially for a multi-user system.
- The TMOUT variable is often used for security purposes to prevent inactive sessions from staying open. Consider the security implications before changing its settings.
- Always back up configuration files before making changes.
If you are unable to change the TMOUT setting, you may need to consult your system administrator for assistance.
FAQs about the TMOUT Variable in Linux
What is the TMOUT variable in Linux?
TMOUT is an environment variable that sets the idle timeout in seconds for a shell session, after which the session automatically logs out if there’s no activity.
How do I set the TMOUT variable?
To set TMOUT, add export TMOUT=number_of_seconds in your shell configuration file (like .bashrc or .bash_profile) or in a global configuration file (like /etc/profile).
Can I disable the TMOUT feature?
Yes, setting TMOUT to 0 disables the auto-logout feature. This can be done by adding export TMOUT=0 in the configuration file.
Does TMOUT affect all shell sessions?
TMOUT affects all shell sessions where it is set. Its scope depends on where you configure it – user-specific or globally for all users.
Is TMOUT applicable to all types of shells?
TMOUT mainly applies to the Bash shell. Other shells might have different mechanisms or might not support this feature.
What happens to running processes when TMOUT logs out a session?
Foreground processes in the session are typically terminated when TMOUT logs out a session, but background processes may continue running.
Can TMOUT improve system security?
Yes, TMOUT enhances system security by automatically logging out idle sessions, preventing unauthorized access to unattended terminals.
Does TMOUT affect remote SSH sessions?
Yes, TMOUT can affect SSH sessions. Idle SSH sessions will be terminated after the set TMOUT duration.
How can I make TMOUT apply only to certain users?
Set TMOUT in the individual user’s shell configuration file to apply it selectively, rather than in global configuration files.
Can TMOUT be overridden by users?
If TMOUT is not set as a readonly variable, users can override it. However, if it’s set as readonly in global configuration files, it cannot be overridden by individual users.
Fix SSH timed out waiting for input: auto-logout with TMOUT and StopIdleSessionSec Configurations
15 SSH Best Practices Every Linux Admin Should Know
Filip
Wednesday 29th of May 2024
Can TMOUT improve system security? Yes, TMOUT enhances system security by automatically logging out idle sessions, preventing unauthorized access to unattended terminals.
Sorry but what? When it is required to go over multiple hops (your workstation included with forced idle timeout) how does it improve security?? Its just super frustrating, and useless, as ppl are just trying to hack around. I'm sick of wannabe security experts (like in our company) which are just taking some lame checklist from web and enforcing it without thinking and thinks they secured the server...
Moneybags
Friday 30th of August 2024
@Filip,
It's more secure because if you leave yourself logged in, and walk away from you machine, there is a time limit to how long someone else can walk up to it and use your credentials.
The DISA STIG as implemented on RHEL 8 and 9 set this TMOUT variable, and yes it improves security.
But I do agree it's very annoying. We used to be able to rely on the assumption that the client machine was secured to lock the screen (and allow the ssh session to run in the background).