Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When using the virtual terminals on TTY 1-6 [*], it's sometimes easy to forget to log out: The screen goes blank after a while, but I'm still logged in - no password required, anyone can use my account. (Or I switch to another TTY, and forget the other one...)

I'd like to have screensaver-like functionality that locks the terminal after 3 minutes, and then requires a password. How do I set this up?


[*] With TTY 1-6, I mean CTRLALTF1 - CTRLALTF6 (no X Server)

share|improve this question
add comment

3 Answers

Implementing a screensaver that way for the TTYs is hard, as you cannot query the X server for the idle time.

If you discipline yourself, you can use the vlock command to explicitly lock a terminal.

A workaround for the timeout approach would be to ssh to localhost and let the ssh connection timeout take care of the rest. The timeout is specified under LoginGraceTime in /etc/ssh/sshd_config and is 120 seconds by default.

If you run exec ssh localhost, you would be automatically logged out when the ssh connection times out. To keep your programs running past the timeout, you could run them via screen.

share|improve this answer
    
Both vlock and exec ssh localhost are great ideas (I will definitely use them)! You're right, it's probably hard to query the idle time without an X server. However, I wonder why the screen does go blank after some time (and wakes up on keypress)? So maybe the same "trigger" could be used to lock the screen automatically somehow? –  Chris Lercher Jun 27 '11 at 14:22
    
I just found out, that the screen blanking (not the locking) can be adjusted by setterm -blank [0-60], see man page. –  Chris Lercher Jun 27 '11 at 15:26
add comment

go to system >> preferences >> screensaver. then choose blank screen, set timer to 3 mins, check 1.activate screensaver when computer is idle, 2 lock screen when screensaver is active.

then open the power management and set "put display to sleep when inactive for" to 3 minutes.

then after 3 minutes of idle time ur computer will activate screensaver, lock ur computer and switch of the display.

share|improve this answer
4  
The screen locking which can be configured in these preferences only applies to the X screen, not to the TTYs. –  Chris Lercher Jun 27 '11 at 14:38
add comment

I know this is old, but I found you on google searching for the same question.

If you’re using bash, it’s no problem. Just use the environment-variable 'TMOUT' which is used by bash for a auto-logout (logout! not lock) in the given seconds.

You can just type ''TMOUT=5'' into any bash an see, what happens.

For configuration in my bashrc I’m using

# autologout on tty1-6 after 30 minutes
if [[ $(tty) =~ /dev\/tty[1-6] ]]; then TMOUT=1800; fi

so I don’t get logged out on a terminal-emulator which is normally on /dev/pty/# and already get locked by my screensaver as part of my desktop

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.