본문 바로가기
서버구축 (WEB,DB)

Terminal auto-lock with zsh and vlock

by 날으는물고기 2014. 12. 19.

Terminal auto-lock with zsh and vlock

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 N seconds.


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.


Just invoke 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 vlock with 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 .zshrc:


And now zsh locks my sessions after 10 minutes. It’s working perfectly even withintmux.


@UPDATE
As the comment from the reader Ehtesh Choudhury we can accomplish that in tmuxonly by adding to your configuration:






출처 : wroot.org


728x90

댓글