Can I set a bash timeout only for virtual consoles (ctrl+alt+{f1-f6})
You could check if you are running in a graphical terminal and only set TMOUT
if you are not. An easy way to do this is the tty
command:
tty - print the file name of the terminal connected to standard input
When run from a GUI terminal emulator:
$ tty
/dev/pts/5
When run from a virtual console:
$ tty
/dev/tty2
So, adding these lines to your ~/.profile
should kill your bash session after ten minutes:
tty | grep tty >/dev/null && TMOUT=600
I never liked the TMOUT solution. First, because it only works if you leave your session at the prompt; if you leave it inside Vim or even at a sudo password prompt, it won't time out. And second, I don't want the session to be closed, I want it to be locked, just like the graphical environments do.
GNU Screen is able to lock after an idle period, so I did the following. At the very beginning of my ~/.bashrc
I added this:
if [ "$TERM" = "linux" ] && tty | egrep -q '^/dev/tty[[:digit:]]+$'
then
exec screen -c ~/.ttyscreenrc
fi
The exec
is important, because it ensures screen
replaces Bash, and when it ends the TTY session will be closed.
And in ~/.ttyscreenrc
I put this:
startup_message off
idle 180 lockscreen
To skip Screen's welcome screen and lock after 3 minutes of inactivity.