brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: TMOUT logs out an idle shell, a simple security setting for shared servers

Security
~/tips/tip-security-tmout-idle-shell-logout

echo 'readonly TMOUT=900; export TMOUT' | sudo tee /etc/profile.d/tmout.sh

Ends an interactive bash session after a set time without input.

An open root shell on a laptop someone walked away from is an open door. Bash can close it on its own with the TMOUT variable.

Set it in a file under /etc/profile.d/, so every login shell picks it up:

echo 'readonly TMOUT=900; export TMOUT' | sudo tee /etc/profile.d/tmout.sh

When a shell waits at the prompt for 900 seconds without a complete line of input, bash prints timed out waiting for input: auto-logout and exits. With SSH that closes the connection too. The readonly part stops a user from simply typing TMOUT=0 to switch it off for their session.

I’d pick the number with some care. Fifteen minutes is fine for an admin box. On a machine where people tail logs or watch a long build, a short value only teaches them to work around it.

It has clear limits. The timer only counts while bash sits at its prompt, so a running top or vim keeps the session alive. Shells inside tmux or screen are logged out, but the tmux server and its other windows stay. Other shells such as zsh and fish handle this differently, and /etc/profile.d only applies to login shells. It is a safety net, not a replacement for locking your screen.

Further reading: Bash manual: Bash Variables (TMOUT)

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link