Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to 'time out' a root shell (for example, in gnome-terminal) so that after a certain amount of time not issuing any commands, the shell exits?

I'm searching for a solution that works in bash on Fedora, and in ksh on OpenBSD.

share|improve this question
add comment

2 Answers

up vote 22 down vote accepted

You can set set the TMOUT variable to a number in seconds that you wish for bash to wait before automatically logging out the shell if no command is run.

share|improve this answer
5  
TMOUT is available both with bash and ksh. –  camh May 6 '11 at 9:10
4  
@camh Zsh too, I would expect any modern shell to support it. –  Arrowmaster May 6 '11 at 9:14
1  
It's a great thing that I learned today. –  SHW May 6 '11 at 10:50
add comment

I know this question is in regards to Bash & Ksh. But I thought I would post something similar for csh/tcsh, for the record.

On FreeBSD, the default shell is tcsh. You can auto logout a session using the autologout feature of the tcsh shell.

The following will autologout a session after one minute of idle activity.

freebsd82# set -r autologout=’1′
(Wait one minute)
freebsd82# auto-logout
Connection to freebsd82 closed.

The tcsh(1) manpage describes it like this:

autologout (+)
     The first word is the number of minutes  of  inactivity  before
     automatic  logout.   The  optional second word is the number of
     minutes of inactivity before automatic locking.  When the shell
     automatically logs out, it prints `auto-logout', sets the vari-
     able logout to `automatic' and exits.  When the shell automati-
     cally locks, the user is required to enter his password to con-
     tinue working.  Five incorrect  attempts  result  in  automatic
     logout.  Set to `60' (automatic logout after 60 minutes, and no
     locking) by default in login and superuser shells, but  not  if
     the shell thinks it is running under a window system (i.e., the
     DISPLAY environment variable is set), the tty is  a  pseudo-tty
     (pty)  or  the shell was not so compiled (see the version shell
     variable).  See also the afsuser and logout shell variables.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.