Auto-logout idle terminal sessions (TMOUT)

Have bash close your shell after a period of inactivity — ideal for shared or lab machines.

Linuxbashauto-logoutsecuritysessionsLow risk
Add TMOUT=900 (and make it readonly) to ~/.bashrc to log out idle shells after 15 minutes.

01Command

Command
$ echo 'TMOUT=900; readonly TMOUT; export TMOUT' >> ~/.bashrc && source ~/.bashrc

02What it does

Bash closes an interactive shell when no input arrives for TMOUT seconds, so an unlocked terminal can't stay open all lunch break. Putting it in ~/.bashrc applies it to your own sessions; setting it readonly plus export stops anyone from casually unsetting it. 900 seconds (15 minutes) is the usual compromise for shared admin boxes.

03Risk

RiskLow risk
!Warning: This kills interactive shells but NOT long-running work detached with tmux/nohup — those keep running; lowering it too far will log you out while you read documentation mid-task.

04Undo

Undo
$ sed -i '/TMOUT=900/d; /readonly TMOUT/d; /export TMOUT/d' ~/.bashrc

05Sources

  • bash(1) — manual page
    Arch Linux · community · 2026-09-17
    Evidence: In interactive shells, bash exits automatically after TMOUT seconds without input; making it readonly prevents users from unsetting it.

Last verified: 2026-09-18 · Category: Security & Privacy

06Related solutions