I’m always concerned about leaving terminal sessions open. I’ve used for many and many years the
$TMOUT environment variable to close my sessions if idle for
Just by exporting the
TMOUT variable to the number of desired timeout seconds will close your shell (Bash, Ksh, Zsh and some others).
The following example will timeout in 300 seconds (5 minutes)
I am currently reading the book Secure Coding: Principles & Practices and the authors cited this timeout technique as pretty ineffective since it annoys more than it helps. I was obliged to agree. I got pretty mad with it some good times.
So I started looking for alternatives.
I’ve found a console application called
vlock. It should be available on most distro’s repositories.
vlock and the terminal session will be locked awaiting the user password to unlock. Pretty nice. Locking is definitely better than killing the session.
So I just started to wonder how to integrate
zsh and after some research I’ve discovered that the shell will only be killed within
TMOUT if no trap function for signal
ALARM is set.
If you set an
ALARM trap function, it will be called instead of killing the session. Perfect.
So I ended up with this in my
zsh locks my sessions after 10 minutes. It’s working perfectly even within
As the comment from the reader Ehtesh Choudhury we can accomplish that in
tmuxonly by adding to your configuration:
출처 : wroot.org