vlock lets you lock your terminal on Linux so no one else can tamper with your system through the command line in your absence.
You may be running commands on your Linux terminal, but might need to step out for a second to get a cup of coffee or do some other task, but you don’t want someone else to be able to run commands on your machine when you’re away from keyboard. What do you do?
vlock is a command-line program that will lock your Linux terminal, as well as virtual consoles.
How to Install vlock on Linux
It’s easy to install vlock on your system. All you have to do is use your distro’s default package manager.
sudo apt install vlock
Arch Linux users can install vlock as part of the kbd package. It’s in the “core” repository and thus installed by default. You can install the package manually if it isn’t:
sudo pacman -S kbd
As with Arch, on an RHEL-based distro like Fedora or CentOS, vlock should be installed by default. But if it isn’t, run:
sudo dnf install kbd
Locking Your Terminal With vlock
When you’ve installed vlock, you can lock your terminal by simply calling it at the command line:
This will clear the screen and display the message, “This TTY is now locked.”
To use your terminal, press Enter and vlock will prompt you for your password. After that, you’ll be able to use your terminal as before.
The root password will also unlock the terminal if it’s enabled. This is useful if another user on the machine ran vlock and forgot their password.
Locking All Virtual Terminals on Linux
While you can lock an individual terminal, a typical Linux desktop has a number of virtual consoles that anyone can switch to if they have physical access to your machine. If you’ve locked one console, someone can launch another instance of the virtual terminal and log in that way.
Fortunately, it’s easy to lock these as well with the -a or –all flag. You’ll have to be actually logged into a virtual console to use this option or it will give an error.
This will lock all the virtual terminals on your system, so nobody will be able to log into them.
Keep Your Linux Machine Safe From Prying Eyes
Locking your terminal with vlock can keep unauthorized users from making changes on the Linux command line if you’ve stepped away from your machine.
If you actually want to be productive with the Linux terminal, Tmux is a great way to have many terminal sessions in one window or virtual console.
Tired of managing multiple terminal windows on Linux? Here’s what you need to know about Tmux.
About The Author