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)