How to Lock Your Terminal Sessions on Linux With vlock

How to Lock Your Terminal Sessions on Linux With vlock

vlock lets you lock your terminal on Linux so no one else can tamper with your system through the command line in your absence.


locking linux terminal vlock

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.

On Debian/Ubuntu:

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:

vlock

This will clear the screen and display the message, “This TTY is now locked.”


vlock-terminal

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.

Related: How to Disable the Root Account in Linux

MAKEUSEOF VIDEO OF THE DAY

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.


vlock locking all virtual consoles on a Debian system

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.

vlock --all

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.


Tmux in Linux
How to Install and Configure Tmux for Linux

Tired of managing multiple terminal windows on Linux? Here’s what you need to know about Tmux.

Read Next


About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *