32

For example, in X session, I can use Ctrl-Alt-L to lock the screen, so it would ask for password to unlock and prevent somebody from messing with mine computer.

But if I have an open terminal session on one of the tty's (which I can access with Ctrl-Alt-F1, for example) - then it is not locked, and somebody can still use it to do some harm. Is there a way to 'lock' that command line (with some background processes running in it, maybe)?

enzotib
  • 50,671
  • 14
  • 120
  • 105
Rogach
  • 6,150
  • 11
  • 38
  • 41

4 Answers4

29

vlock will do as you ask. However, if you want to run background processes, consider screen instead, which will let you also log off and keep processes running in the background, and then reattach -- even when logged in from alternate places.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
wnoise
  • 1,951
  • 1
  • 16
  • 14
  • can't get vlock with plugins, it installs without new.so, thus I can't use vlock -na – Sergius May 06 '16 at 06:50
  • 1
    Use `vlock -a` to lock all virtual terminals (otherwise one could easily switch to a different terminal that might have a user logged in) – friederbluemle Dec 12 '17 at 07:53
  • 2
    @friederbluemle It's worth noting, though, that alt-sysrq-k (alt-printscr-k, of the magic sysrq family) will, depending on configuration, kill the current terminal and vlock with it, allowing somebody to subsequently switch terminals. – Erhannis Feb 08 '19 at 04:36
  • @friederbluemle Good point. It seems there is a `vlock -s` switch to prevent this: "`-s or --disable-sysrq: disable SysRq while consoles are locked to prevent killing vlock with SAK`" – Tony Barganski May 16 '23 at 11:51
11

If you run screen in the terminal, you can lock the terminal with the command Ctrl-a x.

enzotib
  • 50,671
  • 14
  • 120
  • 105
  • 2
    It is also possible to lock a screen session automatically after becoming idle. Just specify `idle 900 lockscreen` in your `.screenrc` to lock the session after being idle for 900 seconds (15 minutes). – scai Jul 30 '13 at 07:35
  • 3
    Be careful with `screen` locks: they do not lock the session but only your particular window into it. Anybody else who can attach to that session with their own window to it will not be locked out. – cjs Jun 20 '17 at 05:53
0

I couldn't get vlock to work un osx, so I created a simple shellscript alternative.

https://github.com/acornejo/bashlock

0

Check out "binarix". It will lock your Terminal. No need for X or screen.

http://raffi.at/view/code/binarix

Anon
  • 1